我拉出我的頭髮。這很簡單,我仍然不明白爲什麼我不斷收到OutOfBounceException。我只創建了一個長度和寬度均爲3的Integer數組。在我看來,這應該包含位置{0123} {0123}。所以p [3] [3]應該完全可以訪問。 PS:我試圖混淆自己的想法,但我似乎無法弄清楚這一點。JAVA:二維數組簡單代碼,但OutOfBounceException
int[][] p = new int[3][3];
p[3][3] = 3;
System.out.println((p[3][3] == 3));
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at test.main(test.java:3)
對於大小爲N的數組,數組索引是類似於:0,1,2,...,N-1。 –
數組不像字典,他們沒有鍵和值,所以把一些東西放在空數組中的位置3只是把它放在第一位。 –
它不是OutOfBounce,而是ArrayIndexOutOfBoundsException。 – tanmoy