posted 22 years ago
Sonir,
I hope you got enough rest for your exam today.
The answer is (e).
The makeArray method creates the following array:
{
{1},
{2, 3},
{4, 5, 6},
{7, 8, 9, 10}
}
Notice the outer array has 4 elements. This results from the statement
int[][] triArray = new int[size][];
Which, when size=4, translates to "create an array that can hold 4 arrays of int".
The for (int i ... ) loop just iterates through these four elements. During each iteration, the following happens:
A new array of int is created and assigned to the
ith element of the outer array in the statement
triArray[i] = new int[i+1]
E.g., when i = 0, the above would evaluate to
triArray[0] = new int[1]; // nested array holds 1 int
and when i = 3, it would evaluate to'
triArray[3] = new int[4]; // nested array holds 4 ints
The for (int j ... ) loop simply assigns values (using and incrementing val) to the elements of the new nested array.
HTH