“Can you look at the following code and point out what’s wrong?”
class TwoDArray {
public static void main( String args[] ) {
int[][] myArray = new int[10][10] ;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 10; j++){
myArray[i][j] = i + j;
System.out.println(myArray[i][j]);
}
}
}
}
“The code given above will result in a NullPointerException
. The reason is that in line 4 , we only allocate memory for the rows . You need to allocate memory for the columns as well.”
This section is wrong, please update this material for future people who use this