+ 4

Can someone explain me this question?

a=true; b=false; c=true; System.out.print (! (a && !(b||c)));

22nd Mar 2019, 1:45 AM
Vanshaj Nathani
Vanshaj Nathani - avatar
3 Answers
+ 9
The output should be true. You need to know how && and || operators work to understand it. The && operator returns true if both of the operands are true. Otherwise returns false. true && true -> true true && false -> false false && true -> false false && false -> false The || operator returns true if at least one of the operands is true. true || true -> true true || false -> true false || true -> true false || false -> false The ! operator returns true if the operand is false and returns false if the operand is true. Now lets see the expression. !(a && !(b || c)) = !(true && !(false || true)) = !(true && !true) = !(true && false) = !false = true
22nd Mar 2019, 2:02 AM
Adnan Zawad Toky
Adnan Zawad Toky - avatar
+ 2
Thanks, got it.
22nd Mar 2019, 2:23 AM
Vanshaj Nathani
Vanshaj Nathani - avatar
+ 2
I was a bit confused in false||true.
22nd Mar 2019, 2:24 AM
Vanshaj Nathani
Vanshaj Nathani - avatar