Tracing Nested Loops on a 2D Array
Consider the following code segment.
int[][] mat = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9},
{10, 11, 12}
};
for (int col = 0; col < mat[0].length; col++)
for (int row = mat.length - 1; row >= col; row--)
System.out.println(mat[row][col]);
When this code is executed, which will be the fifth element printed?
A
5
B
8
C
12
D
11
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE