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

Recursive 2D Array Traversal

Mark
< Prev
Next >

What is printed as a result of executing the following code segment?

public class FlattenArray {
    public static String flatten(int[][] arr, int i, int j) {
        if (i == arr.length) return "";
        if (j == arr[i].length) return flatten(arr, i + 1, 0);
        String separator = (i == arr.length - 1 && j == arr[i].length - 1) ? "" : ",";
        return arr[i][j] + separator + flatten(arr, i, j + 1);
    }
    public static void main(String[] args) {
        int[][] matrix = { {1, 2}, {3, 4} };
        System.out.println(flatten(matrix, 0, 0));
    }
}
A

1234

B

1,2,3,4

C

1, 2, 3, 4

D

1 2 3 4

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|