Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
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

Prints: 1 2 0 3 4

B

Compilation Error

C

Throws an ArrayIndexOutOfBoundsException

D

Prints: 1 2 3 4

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Total 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|FAQ