1)The code output is not single line output.The output is:
size = 1
size = 2
size = 3
size = 4
size = 2
size = 3
size = 3
size = 4
size = 5
size = 6
size = 7
2)Length of x and x[i] are not same
length of x = 3
length of x[0]=4,x[1]=2,x[2]=5
3)Line 3 changes the length ; it allocates objects.If that line is not used we wud get null pointer exception.
My Doubt:
If the code were like:
public class
Test {
public static void main(
String [] args)
{
int [] [] [] x = new int [3] [] [];
int i,j;
x[0] = new int[4][];
x[1] = new int[2][];
x[2] = new int[5][];
for (i=0; i<x.length; i++)
for (j=0; j<x[i].length; j++)
x[i][j] = new int [i + j + 1];
System.out.println("size = " + x[i][j].length);
}
}
I get the compiler error that i and j not initialized....
How come thats possible?
I and j wud have surely initialized in the for loop?