zuai-logo
zuai-logo
  1. AP Computer Science A
FlashcardFlashcardStudy GuideStudy GuideQuestion BankQuestion Bank

2D Arrays in AP Computer Science A

Question 1
Computer Science AAPExam Style
1 mark

What is the general structure for traversing a 2D array?

Question 2
Computer Science AAPExam Style
1 mark

Consider the 'Snaking Around' example. Which part of the code is responsible for alternating the direction of traversal in each row?

Question 3
Computer Science AAPExam Style
1 mark

Which of the following algorithms, when implemented on a 2D array, would require modification of the array's elements and therefore cannot effectively use enhanced for loops for primitive types?

Question 4
Computer Science AAPExam Style
1 mark

Given the 2D array arrayB as defined in the notes, what will be printed by the following code snippet?

java
for (int i = 0; i < arrayB.length; i++) {
    for (int j = 0; j < arrayB[0].length; j++) {
        System.out.print(arrayB[i][j] + " ");
    }
}
Question 5
Computer Science AAPExam Style
1 mark

Which code segment correctly traverses through different columns in reverse order?

Question 6
Computer Science AAPExam Style
1 mark

Given the exampleOne method in the notes (Snaking Around example), what output would be generated if arrayB was a 1x4 array: {{1, 2, 3, 4}}?

Question 7
Computer Science AAPExam Style
1 mark

What is the primary reason why enhanced for loops are not suitable for modifying the original values of primitive types within a 2D array in Java?

Feedback stars icon

How are we doing?

Give us your feedback and let us know how we can improve

Question 8
Computer Science AAPExam Style
1 mark

Given the 2D array arrayB as defined in the notes, what will be the output of the following code?

java
for (int i = arrayB.length - 1; i >= 0; i--) {
    for (int j = arrayB[0].length - 1; j >= 0; j--) {
        System.out.print(arrayB[i][j] + " ");
    }
}
Question 9
Computer Science AAPExam Style
1 mark

Which of the following code snippets correctly implements column-major traversal for a 2D array arr?

Question 10
Computer Science AAPExam Style
1 mark

Given a 2D array of Student objects, where Student has a setName method, can enhanced for loops be used to change the names of the Student objects in the array, and why?