Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AP Computer Science Logical Operators [closed]

Tags:

java

Which of the following will evaluate to true only if boolean expressions A, B, and C are all false?

Answer: !(A || B || C)
My answer: !(A && B && C)

Why is my answer incorrect? If A, B and C are all false and the ! is distributed, it will make all of them true, thus returning true.


Given that a, b and c are integers, consider the boolean expression

(a < b) || !((c == a * b) && (c < a))

Which of the following will guarantee that the expression is true?

Answer: c < a is false

Doesn't the result rely on (c == a * b) being false also because of the &&?

like image 555
Rick Smith Avatar asked Nov 03 '22 03:11

Rick Smith


1 Answers

  1. Keyword: only. If at least one of A,B or C is true, then !(A || B || C) will be false (since A || B || C will be true and ! true is false).

  2. Doesn't the result rely on (c == a * b) being false also because of the &&?

    No: If c < a is false, then (c == a * b) && (c < a) must also be false, meaning that the expression ! ((c == a * b) && (c < a)) must be true, implying that the entire expression must be true (because of the ||, and the fact that we already know right-hand side will be true).

like image 111
arshajii Avatar answered Nov 11 '22 13:11

arshajii