Unit 2 Cycle 2 Day 7: Selection (Two separate if statements)
Share
Unit 2, Selection & Iteration • Cycle 2
Day 7 Advanced Practice • Harder Difficulty
Focus: Independent If Statements
Hard
Selection (Two separate if statements)
Advanced Practice Question
Format: Selection (Two separate if statements)
What is printed?
What is printed?
"apcs-keyword">int n = "apcs-number">12;
"apcs-keyword">if (n % "apcs-number">3 == "apcs-number">0)
{
System.out.print("X");
}
"apcs-keyword">if (n % "apcs-number">4 == "apcs-number">0)
{
System.out.print("Y");
}
else
{
System.out.print("Z");
}
Difficulty: Hard |
Topic: Selection (Two separate if statements) |
Cycle: 2 (Advanced)
Why This Answer?
`12` is divisible by 3, so it prints `X`. It is also divisible by 4, so it prints `Y`. The `else` does not run because the second `if` was true.
Common Mistake
Watch Out!
Thinking the second `if` is connected to the first one (it is not).
AP Exam Strategy
If there are two separate `if`s, they are evaluated independently.
Master This Topic
This Cycle 2 HARD question tests independent if statements. Review Unit 2 concepts to build mastery of selection and iteration.
- Understanding independent if statements
- 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