| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice Test
Share
easy Solved by 3 students
2D Array Loop Boundary Error
< Prev
Next >

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

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1mohammadkhairobeid711 0m 00s 100
#2y.seong202712 5m 39s -249
#3bommasam00024 22m 37s -1,177
APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy