2019/10/31 14:34:15
二维数组
(1)二维表数组定义
声明:
int [][] arrInt=new int[3][3];
(2) 数组的数组
声明:
float [][] arrFloat=new float[3][];
arrFloat[0]=new float[3];
arrFloat[1]=new float[4];
arrFloat[2]=new float[2];
(3)遍历数组
遍历数组:增强的for循环(for…each)
直接输出的码值即是一个数组地址
得到数组长度 数组名.length
二维数组,两种遍历书写方式
int [][] arrInt=new int[3][3];
int arrInt [][]={{2,3,6},{4,6,3},{4,6,4}};
for循环:
for(int i=0;i<arrInt.length;i++) {
for(int j=0;j<arrInt[i].length;j++) {
System.out.print(arrInt[i][j]+" ");
}
System.out.println();
}
增强的for循环:
for (int[] is : arrInt) {
for (int i : is) {
System.out.print(i+" ");
}
System.out.println();
}