Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is `!!(a||!a)` always true?

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

!!(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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading