I'm trying to determine the conditions under which the following expression, where a
and b
are properly declared boolean variables, evaluates to false
:
(a && (b || !a)) == a && b
To me, it seems that this expression will always evaluate to true. If either a
or b
is false
, both sides of the equality operator will evaluate to false
. If a
and b
are both true, then both sides will evaluate to true. That's all the options, and it's the correct answer for my online homework. However, when I run this in IntelliJ CE with the Java 11 JVM, it seems like it prints false whenever b
is false:
when a and b are both false, IntelliJ outputs false
I get the same output when b is false and a is true. Can someone explain where the fault in my logic is? Thank you very much.
I think it is giving
==
operation priority over&&
Try this -