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
easy Solved by 2 students

Enhanced For Loop For 2D Arrays

Mark
< Prev
Next >

Which of the following code segments correctly uses nested enhanced for loops to print all elements of a 2D integer array?

A
int[][] matrix = {{1,2,3},{4,5,6}};
for (int num : matrix) {
    System.out.print(num + " ");
}
B
int[][] matrix = {{1,2,3},{4,5,6}};
for (int i = 0; i < matrix.length; i++) {
    for (int j = 0; j < matrix[0].length; j++) {
        System.out.print(matrix[i][j] + " ");
    }
}
C
int[][] matrix = {{1,2,3},{4,5,6}};
for (int[] row : matrix) {
    System.out.println(row);
}
D
int[][] matrix = {{1,2,3},{4,5,6}};
for (int[] row : matrix) {
    for (int num : row) {
        System.out.print(num + " ");
    }
}
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|