|
大神们好,我阅读《Java入门123》习题源码运行时提示报错,具体是第五章习题第三题,我把答案源码复制到eclipse上运行提示报错:Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 2
at test.test.main(test.java:9)
百度了应该是标值出界,但不懂如何解决,求解惑,谢谢!!
源码:
package test;
public class test {
public static void main(String[] args) {
int size1 = 2;
int size2 = 10;
int[][] array = new int[size2][size1];
int[][] arrayII = array;
for (int i = 0; i < size2; i++) {
arrayII[0][i] = 1;
}
for (int i = 0; i < size2; i++) {
arrayII[1][i] = 1;
}
for (int i = 0; i < size2; i++) {
for (int j = 0; j < size1; j++) {
System.out
.println("[" + i + "]" + "[" + j + "]=" + array[i][j]);
}
}
}
} |
|