0

Why can't I run these source code?

int myArray[4][4], index1, index2; for(index1=0; index1 < 4; index1++) for(index2=0; index2 < 4; index2++) myArray[index1][index2] = index2; for(index1=0; index1 < 4; index1++) { for(index2=0; index2 < 4; index2++){ System.out.print(myArray[index1][index2]); } System.out.println(); }

5th Nov 2021, 7:48 AM
niananno
1 Answer
+ 3
You can't declare an array in java like this. Use new keyword to declare the size. int myArray[][] = new int[4][4]; int index1, index2; for(index1=0; index1 < 4; index1++) for(index2=0; index2 < 4; index2++) myArray[index1][index2] = index2; for(index1=0; index1 < 4; index1++) { for(index2=0; index2 < 4; index2++){ System.out.print(myArray[index1][index2]); } System.out.println(); }
5th Nov 2021, 8:06 AM
Arun Ruban SJ
Arun Ruban SJ - avatar