Modifying A 2D Array With A Method
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
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE