Are you taking CLEP classes? Try clep.ai
| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice TestPractice Test
About Exam
medium

Modifying A 2D Array With A Method

Mark
< Prev
Next >

Consider the following method.

public static void modifyMatrix(int[][] matrix) {
    for (int r = 0; r < matrix.length; r++) {
        for (int c = 0; c < matrix[r].length; c++) {
            if (r != c) {
                matrix[r][c] = -Math.abs(matrix[r][c]);
            } else {
                matrix[r][c] = Math.abs(matrix[r][c]);
            }
        }
    }
}

A 2D array, matrix, is initialized with the following values:

3 -3
-1 2
-4 4

What will be the contents of matrix after the call modifyMatrix(matrix) is executed?

A

-3, -3
-1, 2
-4, 4

B

3, -3
-1, 2
-4, -4

C

3, -3
-1, 2
-4, 4

D

-3, -3
-1, 2
-4, -4

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

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

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