A little confused by this. Can someone correct my logic?

!( 1 < 8 gives a boolean expression of false

false && (5>2 gives a boolean expression of false

false || 3 < 5 gives a boolean expression of true, because one side of this expression is true

A little confused by this. Can someone correct my logic?

!( 1 < 8 gives a boolean expression of false

false && (5>2 gives a boolean expression of false

false || 3 < 5 gives a boolean expression of true, because one side of this expression is true

It does not work and I cannot continue to next page!!

Hello! I faced the same problem

How would you continue to the next exercise? Please let me know.

Try This.

```
public class Precedence {
public static void main(String[] args) {
boolean riddle = !( 1 < 8 && (5 > 2 || 3 < 5));
System.out.println(riddle);
}
}
```

Okay let’s look at our riddle variable.

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

Parentheses have a higher Precedence than !, &&, ||. So for now we will ignore the not(!) boolean operator and we’re left with `( 1 < 8 && (5 > 2 || 3 < 5)`

As you can see there is another expression enclosed in parentheses `(5 > 2 || 3 < 5)`

So lets start there.

`( 5 > 2 || 3 < 5)`

Becomes true.

Now we have `( 1 < 8 && true)`

.

Remember we still haven’t finished evaluating the expression in the parentheses so we’re still ignoring the not operator.

`(1 < 8 && true)`

becomes true and we are now left with `!(true)`

witch is obviously going to be false.

1 Like