Boolean operators: Presedence exercise 5

So the assignment is: “Line 4 has a code statement that is incomplete. Use each Boolean operator no more than once to replace the empty comments /**/. The code statement should print out false.”

So i wrote it like this:

boolean riddle = !( 1 < 8 && (5 > 2 || 3 < 5));

and that’s correct, this prints out ‘false’, but i don’t understand how.

First, 1 is less than 8 so the ! returns out opposite, which is false.
Then, 1 is less than 8 is true and 5 is larger than 2 is also true, so the && should print out true (?)
But then, 5 is bigger than 2 as well as 3 being less than 5, so the || should also print out true (?)

So how does all this print out false? When both && and || is true ?
What have i been mising?

the ! operator changes true to false and false to true. It is a way of saying “not”
Notice it is outside all of the parenthesis

Oh okay so the result of everything -inside- the paranthesis is true, but since the ! is outside it, it turns the total to false. Thanks!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.