What this quiz covers
This quiz focuses on Boolean Expressions, giving you a quick way to practice the rules, question types, and explanations that matter most for AP Computer Science a.
Consider the following Boolean expression: !(a && b) || (c && !d). Given that a = true, b = false, c = true, and d = false, what sequence of evaluations correctly shows how this expression is processed?
!(true && false) evaluates to !false which is true, then true || (true && true) evaluates to true || true which is true!(true && false) evaluates to !true which is false, then false || (true && false) evaluates to false || false which is false!(true && false) evaluates to !false which is true, then true || (true && false) evaluates to true || false which is true!(true && false) evaluates to true, then true || (true && !false) evaluates to true || (true && true) which is falseAP Computer Science a Quiz
Practice Boolean Expressions in AP Computer Science a with focused quiz questions that help you check what you know, review explanations, and build confidence with test-style prompts.
This quiz focuses on Boolean Expressions, giving you a quick way to practice the rules, question types, and explanations that matter most for AP Computer Science a.
Try each quiz question before looking at the correct answer. Use the explanations to review missed ideas, then come back to similar questions until the pattern feels familiar.
Consider the following Boolean expression: !(a && b) || (c && !d). Given that a = true, b = false, c = true, and d = false, what sequence of evaluations correctly shows how this expression is processed?
!(true && false) evaluates to !false which is true, then true || (true && true) evaluates to true || true which is true (correct answer)!(true && false) evaluates to !true which is false, then false || (true && false) evaluates to false || false which is false!(true && false) evaluates to !false which is true, then true || (true && false) evaluates to true || false which is true!(true && false) evaluates to true, then true || (true && !false) evaluates to true || (true && true) which is falsea && b becomes true && false = false. Then !(false) = true. Next, !d becomes !false = true. Then c && !d becomes true && true = true. Finally, true || true = true. Choice A correctly shows this evaluation. Choice B incorrectly negates true instead of false. Choice C incorrectly evaluates !d as false. Choice D contains multiple errors in the logical operations.Consider the expression a && b || c && d. Due to operator precedence, this expression is evaluated as (a && b) || (c && d). If you wanted to force the evaluation to be a && (b || c) && d, which parentheses placement would be correct?
a && (b || c && d) because the parentheses override precedence for the latter portion of the expression only(a && b || c) && d because the parentheses group the first three variables before applying the final conjunctiona && (b || c) && d because the parentheses explicitly group only the disjunction between b and c (correct answer)(a && b) || (c && d) because this maintains the original precedence while adding explicit grouping for claritya && (b || c) && d, we need parentheses around (b || c) to ensure the OR operation happens before the AND operations with a and d. Choice A would evaluate as a && ((b || c) && d) due to AND having higher precedence than OR. Choice B would evaluate as (a && (b || c)) && d, which is equivalent to the desired result but unnecessarily groups a with the parenthetical. Choice D shows the original precedence grouping, not the desired regrouping.In Java, short-circuit evaluation means that in the expression a && b, if a is false, then b is not evaluated. Consider the expression (x != 0) && (y / x > 5). Why is short-circuit evaluation particularly important in this case?
(y / x > 5) would cause a division by zero error, throwing an ArithmeticException. Short-circuit evaluation prevents this by not evaluating the second part when the first part (x != 0) is false. Choice A describes a benefit of short-circuit evaluation but not the critical safety aspect here. Choice C is incorrect about arithmetic types. Choice D is incorrect because the expression evaluates to false due to short-circuiting, not because of logical consistency.A programmer wants to check if a number n is outside the range [10, 50]. They write the condition n < 10 && n > 50. What is wrong with this logic, and what should the correct condition be?
10 > n && 50 < n to maintain consistent directional logicn <= 10 && n >= 50 to include the boundary values in the outside rangen > 10 && n < 50 to check if the number is inside the range instead of outsiden < 10 || n > 50 because a number cannot be both less than 10 and greater than 50 simultaneously (correct answer)n < 10 || n > 50 because OR allows either condition to make the entire expression true.
The original condition n < 10 && n > 50 uses AND, which requires both conditions to be true simultaneously. Since no number can be both less than 10 and greater than 50 at the same time, this condition will always evaluate to false, regardless of the value of n.
Looking at the wrong answers: A) incorrectly focuses on operator direction when the real issue is the logical operator choice. B) suggests changing the comparison operators to include boundaries, but this doesn't fix the fundamental AND/OR problem and would still always be false. C) completely misunderstands the goal by suggesting we check if the number is inside the range instead of outside.
Answer D correctly identifies that OR should replace AND because we need either condition to be true, not both.
Study tip: Remember that "outside a range" typically requires OR logic (either too small OR too large), while "inside a range" uses AND logic (both greater than minimum AND less than maximum).A library allows borrowing when isAvailable && !isReserved; what will happen if isReserved becomes true?
An access system runs while (!hasKeyCard && !isAdmin) to keep showing "Denied"; how does this affect loop iteration?
A traffic-light controller uses if (isEmergency || timeOfDay.equals("NIGHT")); which condition needs to be true to switch to flashing mode?
An access system grants entry when hasKeyCard || isAdmin; what will happen if this condition evaluates to false?
In a game, if (hasPowerUp && !isEnemyNear) allows a speed boost; which condition must be true to execute the boost block?
Which Boolean expression is equivalent to !(a || b) && !(c && d)?
(!a && !b) && (!c || !d) because De Morgan's law applies to both parts of the conjunction independently (correct answer)(!a || !b) && (!c && !d) because negation distributes over the logical operators in each parenthetical group(!a && !b) || (!c || !d) because the outer conjunction becomes disjunction when the entire expression is negated(!a || !b) || (!c && !d) because De Morgan's law converts AND to OR and OR to AND throughout the expression!(a || b) becomes (!a && !b), and !(c && d) becomes (!c || !d). The conjunction between these parts remains unchanged, so the result is (!a && !b) && (!c || !d). Choice B incorrectly applies De Morgan's law to the second part. Choice C incorrectly changes the middle conjunction to disjunction. Choice D incorrectly applies De Morgan's law to the first part and changes the conjunction to disjunction.A method uses the condition (temperature > 80 && humidity > 60) || (temperature > 90). Which statement best describes when this condition evaluates to true?
(temperature > 80 && humidity > 60) || (temperature > 90) is true in two cases: (1) when temperature > 80 AND humidity > 60, or (2) when temperature > 90 (regardless of humidity). Choice A incorrectly suggests temperature > 80 is sufficient alone and that humidity > 60 is sufficient alone. Choice C incorrectly suggests the condition is false when temperature > 90. Choice D incorrectly suggests temperature > 90 alone is insufficient.Consider the expression a || b && c || d. Given Java's operator precedence rules, how is this expression grouped, and what would be an equivalent fully parenthesized version?
((a || b) && c) || d because OR operations are evaluated left to right, then AND operations are applieda || ((b && c) || d) because AND has higher precedence than OR, and OR operations associate right to left(a || b) && (c || d) because the expression is split into two OR operations connected by the AND operationa || (b && c) || d because AND has higher precedence than OR, so the AND operation is grouped first (correct answer)a || b && c || d, the AND operator takes precedence, so b && c is grouped first. This gives us the equivalent expression a || (b && c) || d. The OR operations then associate left to right, but since they're at the same precedence level, the grouping shown captures the essential precedence relationship.
Looking at the wrong answers: Choice A incorrectly assumes OR has higher precedence and groups (a || b) first, which violates Java's precedence rules. Choice B makes two errors—it suggests OR associates right to left (it actually associates left to right) and creates an incorrect grouping that doesn't reflect how Java would actually parse this expression. Choice C completely misinterprets the precedence rules by suggesting the expression splits into two separate OR operations connected by AND, which would require explicit parentheses to achieve.
Choice D correctly identifies that AND has higher precedence than OR, resulting in b && c being grouped first within the larger OR expression chain.
Remember this precedence hierarchy: AND (&&) binds more tightly than OR (||), similar to how multiplication binds more tightly than addition in arithmetic. When in doubt about operator precedence, always add explicit parentheses to make your intentions clear in real code.