Unit 2 Review: Conditions and Branches 🌶️🌶️
A review for the end of Unit 2: boolean operators and their precedence, short-circuit evaluation (counted with a method that records each call), nested and chained ifs, and equivalence. Predict each answer first. For boolean results write true or false; for text, just the characters.
static int calls = 0;public static boolean check(boolean value) { calls++; return value;}public static boolean inRange(int x) { return x >= 10 && x <= 20;}public static String describe(int n) { String r = ""; if (n % 2 == 0) { r += "even"; } else { r += "odd"; } if (n > 10) { r += "+big"; } return r;}
! is done first, then &&, then ||.1. What is the value of true || false && false?
true
2. What is the value of (true || false) && false?
false
3. What is the value of !true || true?
true
4. What is the value of !(5 > 3 && 2 > 4)?
true
5. What is the value of 5 > 3 == true?
true
6. What is the value of 4 % 2 == 0 || 4 / 0 == 1?
true
7. What is the value of 10 > 3 && 7 <= 7?
true
8. What is the value of !(3 < 4) || !(4 < 3)?
true
9. With int a = 4, b = 7; what is the value of a > 3 || b < 2 && a == b?
true
check(v) adds 1 to calls and returns v. Each question starts with calls at 0 and asks for the value of calls afterwards.10. After boolean r = check(false) && check(true); what is calls?
1
11. After boolean r = check(true) || check(true); what is calls?
1
12. After boolean r = check(false) || check(true); what is calls?
2
13. After boolean r = check(true) && check(true) && check(false); what is calls?
3
14. After boolean r = check(true) || check(false) && check(false); what is calls?
1
15. What does describe(7) return?
odd
16. What does describe(12) return?
even+big
17. What does describe(11) return?
odd+big
18. What does describe(4) return?
even
19. How many ints from 0 to 30, inclusive, make inRange return true? (Type a number.)
11
20. How many ints from 0 to 30, inclusive, make describe return a String that ends with big? (Type a number.)
20
21. Which expression is equivalent to !(a >= 0 || b >= 0)?
22. For which value of x do if (x > 5) { p(); } else if (x > 3) { q(); } and if (x > 5) { p(); } if (x > 3) { q(); } behave differently?
Your score for your class is recorded when you click Submit all — checking individual questions doesn't save it. You can submit again to improve your score; your best one counts.