Unit 2 Cycle 2 Day 28: Comprehensive Unit 2 Final Review

Unit 2 Advanced (Cycle 2) Day 28 of 28 Advanced

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.

public static String mystery(String s) { String result = ""; for (int i = 0; i < s.length(); i++) { if (i % 2 == 0) { result += s.substring(i, i + 1).toUpperCase(); } else { result += s.substring(i, i + 1).toLowerCase(); } } return result; }

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.

Review this topic: Section Mixed — Review: All Unit 2 • Unit 2 Study Guide

More Practice

Related FRQs

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.