AP CSA Unit 4 Day 19: 2D Array Search
Share
Unit 4, Data Collections • Cycle 2
Day 19 Advanced Practice • Harder Difficulty
Focus: 2D Array Search
Hard
2D Array Search
Advanced Practice Question
Format: 2D Array Search
What is the output?
What is the output?
int[][] data = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};
boolean found = false;
int target = 5;
for (int r = 0; r < data.length; r++) {
for (int c = 0; c < data[r].length; c++) {
if (data[r][c] == target) {
found = true;
}
}
}
System.out.println(found);
Difficulty: Hard |
Topic: 2D Array Search |
Cycle: 2 (Advanced)
Why This Answer?
Target 5 is found at data[1][1], so found becomes true.
Common Mistake
Watch Out!
Thinking you need to break out of both loops to set found = true.
AP Exam Strategy
Without break, the loops continue but found stays true once set.
Master This Topic
This Cycle 2 HARD question tests 2d array search. Review Unit 4 concepts to build mastery of data collections.
- Understanding 2d array search
- Tracing code execution accurately
- Avoiding common pitfalls
Ready for More Challenges?
Cycle 2 questions prepare you for the hardest AP CSA exam questions.
Study Games Practice FRQs