AP CSA Unit 2.1: Selection and If Statements Practice

Unit 2, Section 2.1
Day 1 Practice • January 7, 2026
🎯 Focus: Making Decisions in Code

Practice Question

Consider the following code segment:
int score = 85;
int bonus = 0;

if (score >= 80) {
    bonus = 10;
}

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

What This Tests: Section 2.1 introduces selection—the ability for programs to make decisions and execute different code based on conditions. The if statement is the fundamental building block for creating programs that respond differently to different situations. This question tests whether you understand how conditions control whether code executes.

Key Concept: Selection with if Statements

An if statement allows code to execute conditionally—only when a condition is true.

if (condition) {
    // This code only runs if condition is true
}
// This code always runs (outside the if)

Key insight: The code inside curly braces {} only executes when the condition evaluates to true. If the condition is false, the code inside is skipped entirely.

Step-by-Step Trace

Line Code score bonus Condition Output
1 int score = 85; 85 - -
2 int bonus = 0; 85 0 -
3 if (score >= 80) 85 0 85 >= 80 → true
4 bonus = 10; 85 10 (executes)
6 score = score + bonus; 95 10 -
7 println(score); 95 10 - 95

Final output: 95

Why: Since 85 >= 80 is true, the if statement body executes, setting bonus to 10. Then score becomes 85 + 10 = 95.

Common Mistakes

Mistake 1: Answer A (80)

This would be correct if we printed the threshold value from the condition, but we print score, not the number 80. The condition score >= 80 evaluates to true or false, it doesn't change score to 80.

Mistake 2: Answer B (85)

This mistake comes from thinking the if statement doesn't execute, or forgetting that score gets updated on line 6. The condition 85 >= 80 is true, so bonus becomes 10, and then score = 85 + 10 = 95, not 85.

Mistake 3: Answer C (90)

This is close but uses the wrong arithmetic. Some students might think bonus = 5 instead of 10, or miscalculate 85 + 10. Always trace carefully and double-check your arithmetic.

Mistake 4: Answer E (10)

This prints the value of bonus instead of score. The println statement prints score, which is 95 after the addition, not bonus which is 10.

Understanding If Statement Flow

// Step 1: Evaluate the condition
if (score >= 80)  // Is 85 >= 80? YES → true

// Step 2: Since true, execute the body
{
    bonus = 10;  // This line DOES execute
}

// Step 3: Continue with code after if
score = score + bonus;  // Always executes (outside if)

If the condition were false:

int score = 75;  // Changed to 75
int bonus = 0;

if (score >= 80)  // Is 75 >= 80? NO → false
{
    bonus = 10;  // This line SKIPPED
}

score = score + bonus;  // 75 + 0 = 75
System.out.println(score);  // Prints 75

Practice Technique

The If Statement Decision Tree Method

When tracing if statements, ask yourself these questions in order:

  1. What is the condition? (Write it down)
  2. What are the current variable values? (Check your trace table)
  3. Substitute values into the condition (e.g., 85 >= 80)
  4. Evaluate: true or false? (Be precise)
  5. If true: Execute the body, update variables
  6. If false: Skip the body entirely
  7. Continue with code after the if

Never guess—always trace!

Additional Examples

Example 1: Temperature Check
int temp = 72;
String message = "Normal";

if (temp > 75) {
    message = "Hot";
}

System.out.println(message);  // Prints "Normal"
// Because 72 > 75 is false, if body skipped
Example 2: Grade Adjustment
int grade = 88;

if (grade >= 90) {
    grade = grade + 5;  // Skipped (88 >= 90 is false)
}

System.out.println(grade);  // Prints 88
Example 3: Multiple Operations in If
int x = 100;
int y = 50;

if (x > y) {  // 100 > 50 is true
    x = x - 20;  // x becomes 80
    y = y + 20;  // y becomes 70
}

System.out.println(x + " " + y);  // Prints "80 70"

Related Topics

  • Section 2.2: Boolean Expressions (conditions that evaluate to true/false)
  • Section 2.3: if Statements and Control Flow (single-path decisions)
  • Section 2.4: if-else Statements (two-path decisions)
  • Section 2.7: while Loops (repetition with conditions)
  • Section 2.9: Implementing Algorithms with Selection
Difficulty: Medium • Time: 2-3 minutes • AP Skill: 2.B - Implement and apply an algorithm

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 with 1,700+ hours experience • 5.0 rating

Back to blog

Leave a comment

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