在Java中,創建二維數組的方式有以下幾種:
int[][] twoDArray = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int[][] twoDArray = new int[3][3];
twoDArray[0][0] = 1;
twoDArray[0][1] = 2;
twoDArray[0][2] = 3;
// 繼續為其他元素賦值
int[] row1 = {1, 2, 3};
int[] row2 = {4, 5, 6};
int[] row3 = {7, 8, 9};
int[][] twoDArray = {row1, row2, row3};
int[][] originalArray = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
int[][] clonedArray = originalArray.clone();