+ 4
Can someone explain me this question?
a=true; b=false; c=true; System.out.print (! (a && !(b||c)));
3 Antworten
+ 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
+ 2
Thanks, got it.
+ 2
I was a bit confused in false||true.