AP CSA Unit 4 Day 10: Array Algorithm Find Maximum
Share
Unit 4, Data Collections • Cycle 2
Day 10 Advanced Practice • Harder Difficulty
Focus: Array Algorithm: Find Maximum
Hard
Array Algorithm: Find Maximum
Advanced Practice Question
Format: Array Algorithm: Find Maximum
What is the output?
What is the output?
int[] nums = {3, 7, 2, 9, 5};
int max = nums[0];
for (int i = 0; i < nums.length; i++) {
if (nums[i] > max) {
max = nums[i];
}
}
System.out.println(max);
Difficulty: Hard |
Topic: Array Algorithm: Find Maximum |
Cycle: 2 (Advanced)
Why This Answer?
Standard find max algorithm. Starts with max=3, updates to 7, keeps 7, updates to 9, keeps 9. Maximum is 9.
Common Mistake
Watch Out!
Starting max at 0 instead of nums[0] when array could contain negative numbers.
AP Exam Strategy
Always initialize max to first element (nums[0]), not to 0.
Master This Topic
This Cycle 2 HARD question tests array algorithm: find maximum. Review Unit 4 concepts to build mastery of data collections.
- Understanding array algorithm: find maximum
- 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