A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© lclxjzz 中级黑马   /  2015-4-21 20:38  /  419 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. <p>class Array3Demo
  2. {
  3.         public static void main(String[] args)
  4.         {
  5.                 int arr[][]=new int[3][];                     
  6.                 Print(arr,3);                                 
  7.         }                                                  
  8.         public static void Print(int arr[][],int a){      
  9.                 for(int x=0;x<arr.length;x++){               
  10.                         System.out.println(arr[x]);               
  11.                 }
  12.         }
  13. }
  14. <img alt="" src="http://bbs.itheima.com/forum.php?mod=image&aid=69926&size=300x300&key=9be6b41613125b74&nocache=yes&type=fixnone" border="0" aid="attachimg_69926">


  15. class Array3Demo
  16. {
  17.         public static void main(String[] args)
  18.         {
  19.                 int arr[][]=new int[3][4];                     
  20.                 Print(arr,3,4);                                 
  21.         }                                                  
  22.         public static void Print(int arr[][],int a,int b){
  23.                 for(int x=0;x<arr.length;x++){
  24.                         for(int y=0;y<arr[x].length;y++){
  25.                                 System.out.print("arr["+x+"]["+y+"]="+arr[x][y]+"\t");
  26.                         }
  27.                         System.out.println();
  28.                 }
  29.         }
  30. }</p><p>
  31. </p><p><img alt="" src="http://bbs.itheima.com/forum.php?mod=image&aid=69927&size=300x300&key=36721bf38fdc9367&nocache=yes&type=fixnone" border="0" aid="attachimg_69927"></p><p><font style="background-color: rgb(247, 247, 247);">因为在new一个二维数组时,左边的没有初始化数组中控制一维数组的长度值,而一维数组默认初始化值为null,所以打印结果为null而后一个程序对一维数组进行了初始化赋值,一维数组值不为null,打印的事二维数组默认初始化值(才学,不足之处望大神讲解!!)</font>
  32. </p>
复制代码

QQ图片20150421203255.png (856 Bytes, 下载次数: 0)

QQ图片20150421203255.png

QQ图片20150421203304.png (1.81 KB, 下载次数: 0)

QQ图片20150421203304.png

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马