public class MultiDimen {
public static void main(String[] arg) {
int firstArray[][] = { { 8, 9, 19, 11 }, { 12, 13, 14, 15 }, };
int secondArray[][] = { { 30, 31, 32, 33 }, { 43 }, { 4, 5, 6, }, };
System.out.println("This is the first Array");
display(firstArray);
System.out.println("This is the second Array");
display(secondArray);
}
public static void display(int x[][]) {
for (int row = 0; row < x.length; row++) {
System.out.println("ROW:" + x[row].length + "[row].length");
for (int column = 0; column < x[row].length; column++) {
System.out.print(x[row][column] + "\t");
}
System.out.println();
}
}
}
我明白這裏發生了什麼,但是,有一點不清楚的是x [row] .length的作用是什麼? 我知道x.length獲得傳入的colomns x數組的長度。但row不是一個數組,它被聲明爲int,所以我們爲什麼要這樣做?x [row] .length做什麼?
,因爲它是它報告X [行]的陣列長度的二維陣列 –
'length'是內置的Java中的數組的屬性。它用於確定任何數組的大小。 – Keerthivasan