APFIVE APFIVE | preferred AP College board partner for AP classes
Login
 
Register
AP Classes
AP Human Geography AP Computer Science A AP Comparative Government and Politics AP European History AP Macroeconomics AP Microeconomics AP Psychology AP United States Government and Politics AP United States History AP Calculus AB AP Calculus BC AP Computer Science Principles AP Precalculus AP Statistics AP Biology AP Chemistry AP Environmental Science AP Chinese AP Art History AP English Literature AP Research AP Spanish Literature AP Art & Design AP World History: Modern AP English Language AP French AP German AP Japanese AP Latin AP Italian AP Spanish Language AP Music Theory AP Physics 1 AP Physics 2 AP Physics C: Mechanics AP Physics C: E&M AP African American Studies
AP Computer Science A/Unit 8: 2D Array
Start Practice Test
Share
2D Array Loop Boundary Error
< Prev
Next >

What is the outcome when the following code is executed?

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

Throws an ArrayIndexOutOfBoundsException

B

Compilation Error

C

Prints: 1 2 3 4

D

Prints: 1 2 0 3 4

Check Answer
APFIVE © 2020.
Email: [email protected]|Privacy Policy