2D Array Loop Boundary Error
What is the outcome when the following code is executed?
public class MatrixError {
public static void main(String[] args) {
int[][] grid = { {1,2}, {3,4} };
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j <= grid[i].length; j++) {
System.out.print(grid[i][j] + " ");
}
}
}
}
A
Throws an ArrayIndexOutOfBoundsException
B
Compilation Error
C
Prints: 1 2 3 4
D
Prints: 1 2 0 3 4
APFIVE