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

Which matrix will be the result of a call to modifyMatrix(matrix)?

A matrix (two-dimensional array) is declared as int[][] matrix = new int[3][2];
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]);
            }
        }
    }
}

If matrix is initialized to be:

3, -3

-1, 2

-4, 4
Which matrix will be the result of a call to modifyMatrix(matrix)?

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

Question Leaderboard

Not enough data yet to show leaderboard.

AI Tutor

How can I help?

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