2D Array Loop Boundary Error
What is the result of executing the following code?
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
Compilation Error
B
Throws an ArrayIndexOutOfBoundsException
C
Prints: 1 2 3 4
D
Prints: 1 2 0 3 4
Question Leaderboard
| Rank | |||||
|---|---|---|---|---|---|
| #1 | mohammadkhairobeid7 | 1 | 1 | 0m 00s | 100 |
| #2 | y.seong2027 | 1 | 2 | 5m 39s | -249 |
| #3 | bommasam000 | 2 | 4 | 22m 37s | -1,177 |
APFIVE