Are you taking CLEP classes? Try clep.ai
| 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

Mark
< Prev
Next >

Consider the following transform method, which modifies a 2D array of integers.

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;
    }
  }
}

Which statement best describes the state of the grid array after the transform method has been executed?

A

Every element’s sign is toggled twice if both the left and upper elements are negative.

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

All negative values in the array are changed to positive.

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.

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy|