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

What is the output when the program is run?

public class TransposePrint {
    public static void printTranspose(int[][] arr, int col, int row) {
        if (col == arr[0].length) return;
        if (row == arr.length) {
            System.out.println();
            printTranspose(arr, col + 1, 0);
            return;
        }
        System.out.print(arr[row][col] + " ");
        printTranspose(arr, col, row + 1);
    }
    public static void main(String[] args) {
        int[][] mat = { {1, 2, 3}, {4, 5, 6} };
        printTranspose(mat, 0, 0);
    }
}
A

1 4 2 5 3 6

B

1 4
2 5
3 6

C

4 1
5 2
6 3

D

1 2 3 4 5 6

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