Are the following Boolean expressions true or false? Assume variables x = 5 and y = 6.
!(x > 6)       _________
(x==6 && x==5) _________
(x==6 || x==5) _________
(x>-1 && y<10) _________
Although the syntax is correct, what is flawed about the following Boolean expression?
(x > 10 && x < 5)  ________________________________
Answers:
!(x > 6)       true
(x==6 && x==5) false
(x==6 || x==5) true
(x>-1 && y<10) true
(x > 10 && x < 5) 
The above can never be true! A number can never be greater than ten AND less than five.

4 Comments

»

  1. Wait, so how can x==6 || x==5 be true if x=5? I got the others right. Is this meaning that in some cases 5 == 6?

    Comment by Gabe — October 20, 2009 @ 9:46 pm

  2. Ah, I got it now. Thanks anywho.

    Comment by gabriel mathews — October 21, 2009 @ 8:50 am

  3. I have the same question, how can x==6?

    Comment by Emily — January 26, 2010 @ 3:17 pm

  4. x does not equal 6, x equals five. However, in the following expression:

    (x==6 || x==5)
    

    the || represents an “or” meaning if x is equal to 6 OR x is equal to 5. And it is equal to 5. so the entire expression is true.

    In the case of an AND:

    (x==6 && x==5)
    

    since x cannot be both 6 and 5 at the same time, that expression is clearly false.

    Comment by Daniel Shiffman — January 26, 2010 @ 6:50 pm

Leave a comment