Unit 2 Cycle 2 Day 5: Boolean Precedence (&& before ||)

Unit 2, Selection & Iteration • Cycle 2
Day 5 Advanced Practice • Harder Difficulty
Focus: Operator Precedence Hard Boolean Precedence (&& before ||)

Advanced Practice Question

Format: Boolean Precedence (&& before ||)

What is printed?
"apcs-keyword">int a = "apcs-number">3;
"apcs-keyword">int b = "apcs-number">7;

"apcs-keyword">boolean result = (a > "apcs-number">3) || (b / a == "apcs-number">2) && (b % a == "apcs-number">1);

System.out.println(result);
Difficulty: Hard  |  Topic: Boolean Precedence (&& before ||)  |  Cycle: 2 (Advanced)
Why This Answer?

`a > 3` is false. `b / a` is `7 / 3` which is 2 (integer division), so `(b / a == 2)` is true. `b % a` is 1, so `(b % a == 1)` is true. `true && true` is true, so `false || true` is true.

Common Mistake
Watch Out!

Evaluating left-to-right and treating `||` as having the same precedence as `&&`.

AP Exam Strategy

Remember: `&&` groups tighter than `||` unless parentheses force a different grouping.

Master This Topic

This Cycle 2 HARD question tests operator precedence. Review Unit 2 concepts to build mastery of selection and iteration.

  • Understanding operator precedence
  • Tracing code execution accurately
  • Avoiding common pitfalls
View Unit 2 Study Guide

Ready for More Challenges?

Cycle 2 questions prepare you for the hardest AP CSA exam questions.

Study Games Practice FRQs
Back to blog

Leave a comment

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