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