Java中二維數(shù)組的初始化方式有以下幾種:
int[][] arr = {{1, 2, 3}, {4, 5, 6}};
int[][] arr = new int[2][3];
arr[0][0] = 1;
arr[0][1] = 2;
arr[0][2] = 3;
arr[1][0] = 4;
arr[1][1] = 5;
arr[1][2] = 6;
int[][] arr = new int[2][];
arr[0] = new int[3];
arr[1] = new int[2];
arr[0][0] = 1;
arr[0][1] = 2;
arr[0][2] = 3;
arr[1][0] = 4;
arr[1][1] = 5;
int[][] arr = new int[2][3];
int num = 1;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
arr[i][j] = num;
num++;
}
}