上面没写完,这是全的
public class TestArr {
/**
* @param args
*/
public static void main(String[] args) {
/*int[][] arr ={{1,2,3},{4,5,7,8},{9,8}};
for (int i = 0;i <arr.length ;i++ ) {
for (int j = 0;j <arr.length ;j++ ) {
System.out.print(arr[j]); //打印的是什么?
}
System.out.println();
}
打印结果如下:
[I@3e30e173[I@7b2164ea[I@4d687dcd
[I@3e30e173[I@7b2164ea[I@4d687dcd
[I@3e30e173[I@7b2164ea[I@4d687dcd
*/
int[][] arr = { { 1, 2, 3 }, { 4, 5, 7, 8 }, { 9, 8 } };
traverse(arr);
/*打印结果如下:
1,2,3
4,5,7,8
9,8
*/
}
public static void traverse(int[][] arr) {
for (int i = 0; i < arr.length; i++) {
int[] arr2=arr[i];
for (int j = 0; j < arr2.length; j++) {
if(j!=arr2.length-1)
System.out.print(arr2[j]+",");
else
System.out.print(arr2[j]);
}
System.out.println();
}
}
}
|