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(); }
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();
}