| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice Test
Share
medium Solved by 2 students
Modifying a 2D Array in a Method
< Prev
Next >

What is printed when the following program is executed?

public class ModifyArray {
    public static void modify(int[][] matrix) {
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[i].length; j++) {
                matrix[i][j] += i;
            }
        }
    }
    public static void main(String[] args) {
        int[][] grid = { {1,2}, {3,4} };
        modify(grid);
        System.out.print(grid[1][0] + " " + grid[1][1]);
    }
}
A

4 6

B

4 5

C

5 5

D

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
#1bommasam00024 0m 49s 131
#2upadhgau00002 0m 00s -20
#3y.seong202714 147h 56m -532,536
APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy