| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice Test
Share
easy Solved by 5 students
2D Array Traversal With Step
< Prev
Next >

Consider the following method.

public void editArray(int[][] data) {
    for (int row = 0; row < data.length; row += 2) {
        for (int col = 0; col < data[row].length; col++) {
            data[row][col] = -data[row][col];
        }
    }
}

An int[][] array, arr, is declared and initialized as follows.

int[][] arr = {
    {-1, -2, -3},
    {4, 5, 6},
    {7, 8, 9},
    {10, 11, 12}
};

What are the contents of arr after the method call editArray(arr) is executed?

A

1, 2, 3
4, 5, 6
-7, -8, -9
10, 11, 12

B

-1, -2, -3
4, 5, 6
7, 8, 9
10, 11, 12

C

1, 2, 3
4, 5, 6
7, 8, 9
10, 11, 12

D

1, 2, 3
4, 5, 6
-7, -8, -9
-10, -11, -12

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

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1kaisuki11 0m 00s 100
#2y.seong202712 1m 40s -10
#3winstonhou110701 0m 00s -10
#4bommasam00013 11m 52s -632
APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy