Analyzing a 2D Array Transformation Method
Consider the following Java method defined to modify a 2D array of integers where each element is evaluated and adjusted based on its neighboring elements.
public static void transform(int[][] grid) {
for (int i = 0; i < grid.length; i++) {
for (int j = 0; j < grid[i].length; j++) {
if (i > 0 && grid[i-1][j] < 0) grid[i][j] *= -1;
if (j > 0 && grid[i][j-1] < 0) grid[i][j] *= -1;
}
}
}
Choose the statement that best describes the modified values in the 2D array grid after executing the method.
A
All negative values in the array are changed to positive.
B
Elements on even rows are negated if the element above them in the previous row is negative.
C
Elements have their signs changed if either the element to their left or the element above them is negative.
D
Every element’s sign is toggled twice if both the left and upper elements are negative.
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE