在Java中,定義二維數組的方式有以下幾種:
int[][] arr = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int[][] arr = new int[3][3];
arr[0] = new int[]{1, 2, 3};
arr[1] = new int[]{4, 5, 6};
arr[2] = new int[]{7, 8, 9};
int[][] arr = new int[3][3];
int[][] arr = new int[3][3];
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
arr[i][j] = i * arr.length + j + 1;
}
}