I want to create a matrix in java .. I implemented the following code
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]);
}
}
When I run the code I get the following error :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at shapes.Tester.main(Tester.java:8)
I tried different methods to correct the code but nothing was helpful Can you please correct the code for me ?
thank you
for
loop