| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice TestPractice Test
About Exam
hard
Analyzing a 2D Array Transformation Method
< Prev
Next >

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.

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.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

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