for (int r = 0; r <= grid.length; r++) {
for (int c = 0; c < grid[0].length; c++) {
grid[r][c] = 0;
}
}Which fix corrects the bounds error?
- Acheck_circle
Change r <= grid.length to r < grid.length
- B
Swap rows and columns
- C
Use grid[r-1][c]
- D
Change c < grid[0].length to c <= grid[0].length
Explanation
Row indices run 0 to grid.length-1. The outer condition must be r < grid.length to avoid an out-of-bounds access.