| preferred AP College board partner for AP classes
AP Computer Science A/Unit 8: 2D Array
Start Practice TestPractice Test
About Exam
hard Solved by 1 students
Recursive 2D Array Traversal
< Prev
Next >

What is the printed output when this program is executed?

public class ReversePrint {
    public static void printReverse(int[][] arr, int i, int j) {
        if (i < 0) return;
        if (j < 0) {
            printReverse(arr, i - 1, arr[0].length - 1);
            return;
        }
        System.out.print(arr[i][j] + " ");
        printReverse(arr, i, j - 1);
    }
    public static void main(String[] args) {
        int[][] grid = { {1, 2}, {3, 4} };
        printReverse(grid, grid.length - 1, grid[0].length - 1);
    }
}
A

4 3 2 1

B

1 2 3 4

C

4 2 3 1

D

1 4 3 2

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