| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice TestPractice Test
About Exam
easy Solved by 5 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

Prints: 1 2 0 3 4

B

Throws an ArrayIndexOutOfBoundsException

C

Compilation Error

D

Prints: 1 2 3 4

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1mohammadkhairobeid711 0m 00s 100
#2y.seong202712 5m 39s -249
#3bommasam00024 22m 37s -1,177
Items per page:
10
1 – 3 of 3
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy