Unit 2 Cycle 2 Day 28: Comprehensive Unit 2 Final Review
Share
Comprehensive Unit 2 Final Review
Section Mixed — Review: All Unit 2
Key Concept
This Unit 2 final review covers all selection and iteration topics at exam-level difficulty. Unit 2 is the most heavily tested unit on the AP CSA exam, representing approximately 17-22% of all questions. The most critical topics to master are: De Morgan's Laws transformations, short-circuit evaluation with null checks, off-by-one loop errors, nested loop iteration counts, string traversal algorithms, and the relationship between for and while loop equivalence. Expect the AP exam to combine two or three of these concepts in each question.
Consider the following method.
What does mystery("hello") return?
Answer: (A) HeLlO
Index 0(even): "h"→"H". Index 1(odd): "e"→"e". Index 2(even): "l"→"L". Index 3(odd): "l"→"l". Index 4(even): "o"→"O". Result: "HeLlO".
Why Not the Others?
(B) This would be the result if odd indices were uppercased and even were lowercased (the opposite).
(C) This would require all characters to be uppercased, ignoring the even/odd condition.
(D) This would require all characters to be lowercased, ignoring the condition.
Common Mistake
Even-indexed characters (0, 2, 4) are uppercased; odd-indexed (1, 3) are lowercased. The alternating case pattern is determined by the index, not the original case.
AP Exam Tip
toUpperCase() and toLowerCase() are String methods that return new Strings. They do not modify the original. The AP exam sometimes includes these in string traversal problems.