我想在Java中创建一个矩阵.. 我已经实现了以下代码
当我运行代码时,出现以下错误:
public class Tester {
public static void main(String[] args) {
int[][] a = new int[2][0];
a[0][0] = 3;
a[1][0] = 5;
a[2][0] = 6;
int max = 1;
for (int x = 0; x < a.length; x++) {
for (int b = 0; b < a[x].length; b++) {
if (a[x][b] > max) {
max = a[x][b];
System.out.println(max);
}
System.out.println(a[x][b]);
}
}
System.out.println(a[x][b]);
}
}
当我运行代码时,出现以下错误:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at shapes.Tester.main(Tester.java:8)
我尝试了不同的方法来纠正代码,但都没有起到帮助作用。您能否为我纠正代码?
谢谢
for
循环之外是不可见的。 - MGoksu