AP CSA Unit 2.3: If-Else Chains and Grade Assignment Practice

Unit 2, Section 2.3
Day 3 Practice • January 9, 2026
🎯 Focus: if-else Chains

Practice Question

Consider the following code segment:
int grade = 75;
String result;

if (grade >= 90) {
    result = "A";
} else if (grade >= 80) {
    result = "B";
} else if (grade >= 70) {
    result = "C";
} else {
    result = "F";
}

System.out.println(result);
What is printed as a result of executing this code segment?

What This Tests: Section 2.3 covers if-else chains. Once a condition is true and its block executes, all remaining else-if and else blocks are skipped. Only ONE branch executes.

Key Concept: If-Else Chain Execution

Java evaluates conditions top to bottom. The FIRST true condition's block executes, then the entire chain is done.

grade = 75

if (grade >= 90)      // 75 >= 90? false → skip
else if (grade >= 80) // 75 >= 80? false → skip
else if (grade >= 70) // 75 >= 70? TRUE → execute!
    result = "C";      // This runs
else                  // Skipped (already found true)

Step-by-Step Trace

Condition grade=75 Result Action
grade >= 90 75 >= 90 false Skip to next
grade >= 80 75 >= 80 false Skip to next
grade >= 70 75 >= 70 true Execute block!
else - - Skipped

Output: C

Common Mistakes

Mistake: Answer E (CF)

Only ONE branch executes in an if-else chain. Once 75 >= 70 is true and result = "C" runs, the else block is skipped entirely.

Order Matters!

If the conditions were reversed (checking >= 70 first), a grade of 95 would get "C"! Always order from highest to lowest threshold.

Practice Technique

Tracing If-Else Chains
  1. Start at the first if
  2. Evaluate the condition
  3. If true → execute that block, DONE
  4. If false → move to next else-if or else
  5. Repeat until you find true or reach else

Related Topics

  • Section 2.1: Simple if Statements
  • Section 2.4: Nested if Statements
  • Section 2.5: Compound Boolean Expressions
Difficulty: Medium • Time: 2-3 minutes • AP Skill: 2.B - Determine code results

Ready to Level Up Your AP CSA Skills?

Get personalized help or access our complete question bank

Premium Question Bank - Coming Soon! Schedule 1-on-1 Tutoring

400+ Unit 2 questions • Expert tutoring • 5.0 rating

Back to blog

Leave a comment

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