| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice Test
Share
hard Solved by 7 students
Recursive 2D Array Row Reversal
< Prev
Next >

What is printed when the following program is executed?

public class ReverseRow {
    public static void reverseRow(int[] row, int start, int end) {
        if (start >= end) return;
        int temp = row[start];
        row[start] = row[end];
        row[end] = temp;
        reverseRow(row, start + 1, end - 1);
    }
    public static void reverseAll(int[][] arr, int i) {
        if (i == arr.length) return;
        reverseRow(arr[i], 0, arr[i].length - 1);
        reverseAll(arr, i + 1);
    }
    public static void main(String[] args) {
        int[][] grid = { {1, 2, 3}, {4, 5, 6} };
        reverseAll(grid, 0);
        for (int i = 0; i < grid.length; i++) {
            for (int n : grid[i]) {
                System.out.print(n + " ");
            }
            System.out.println();
        }
    }
}
A

1 2 3
6 5 4

B

3 2 1
4 5 6

C

3 2 1
6 5 4

D

1 2 3
4 5 6

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer

Question Leaderboard

Not enough data yet to show leaderboard.

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