1.声明并初始化
//一维:
int[] i = new int[12];
i[0] = 12;
int[] j = new int[]{12,3};
//二维:
1)String[][] str = new String[4][3]; //4行3列
2)String[][] str1 = new String[4][];
str1[0] = new String[3];
...
str1[3] = new String[5];
3)
int[][] arr = new int[][]{{1,2,3},{4,5},{6}};
2.如何引用二维数组的元素:arr[1][0] = 12;
3.二维数组的长度:arr.length;//3
arr[1].length;//2
4.遍历二维数组
for(int i = 0;i < arr.length;i++){
for(int j = 0;j < arr[i].length;j++){
System.out.print(arr[i][j] + "\t");
}
System.out.println();
}
//一维:
int[] i = new int[12];
i[0] = 12;
int[] j = new int[]{12,3};
//二维:
1)String[][] str = new String[4][3]; //4行3列
2)String[][] str1 = new String[4][];
str1[0] = new String[3];
...
str1[3] = new String[5];
3)
int[][] arr = new int[][]{{1,2,3},{4,5},{6}};
2.如何引用二维数组的元素:arr[1][0] = 12;
3.二维数组的长度:arr.length;//3
arr[1].length;//2
4.遍历二维数组
for(int i = 0;i < arr.length;i++){
for(int j = 0;j < arr[i].length;j++){
System.out.print(arr[i][j] + "\t");
}
System.out.println();
}
5.二维数组的结构: