- <p>class Array3Demo
- {
- public static void main(String[] args)
- {
- int arr[][]=new int[3][];
- Print(arr,3);
- }
- public static void Print(int arr[][],int a){
- for(int x=0;x<arr.length;x++){
- System.out.println(arr[x]);
- }
- }
- }
- <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">
- class Array3Demo
- {
- public static void main(String[] args)
- {
- int arr[][]=new int[3][4];
- Print(arr,3,4);
- }
- public static void Print(int arr[][],int a,int b){
- for(int x=0;x<arr.length;x++){
- for(int y=0;y<arr[x].length;y++){
- System.out.print("arr["+x+"]["+y+"]="+arr[x][y]+"\t");
- }
- System.out.println();
- }
- }
- }</p><p>
- </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>
- </p>
复制代码
|
|