2D Array Nested Loop Output
Consider the following code segment:
int [][] matrix = {{1, 1, 1}, {2, 2, 2}, {3, 3, 3}};
for (int i = 0; i < matrix.length; i++)
for (int j = 0; j < matrix[i].length; j++)
System.out.print(matrix[i][j] * 2 + " ");
System.out.print("\n");
What is printed as a result of executing the code segment?
A
A runtime error occurs.
B
2 2 2
4 4 4
6 6 6
C
2 4 6 2 4 6 2 4 6
D
2 2 2 4 4 4 6 6 6
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE