I’m a Java rookie and in School we got some homework. I shall explain boolean terms but I don’t understand one of them.
The question is
Why is this expression always true?
!!(a||!a)
I understand the part in the brackets but what do the two exclamation marks in front of it?
If the first a = true –> !a = not true –> !! ( double negation = true?) a = true and the second !a = not true –> !!a = true –> !!!a = not true
and if I’m right , why is this expression alsways true? That beats me.
Could any of you explain that to me?
Thanks for your help!
>Solution :
First off, !! expression cancels out: it’s the same as expression, because the negation of a negation is the original value.
So we’re left with a || ! a, which is a disjunction. So the result is true if at least one of the sub-expressions a or !a is true.
And lastly, a is true if a is true (duh). And ! a is true if a is false. Thus, regardless of the value of a, the overall expression is true.