# Exercise 5 : Precendence

<PLEASE USE THE FOLLOWING TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<In what way does your code behave incorrectly? Include ALL error messages.>

```

public class Precedence {
public static void main(String args) {

``````	boolean riddle = true;
riddle =( (1 < 8) || (5 > 2 || 3 < 5));
System.out.println(riddle);

}
``````

}

i don’t understand this exercise. My code statement print “false” but i can’t pass this exercise

``<do not remove the three backticks above>``

hi
boolean riddle =!(1>8)&&(5<2 || 3<5));
if it errors click (Get help { right and down }, i want to restart this exercise) then write upper code again:)

1 Like

hi
boolean riddle = !( 1 < 8 || (5 > 2 && 3 < 5));
try dis out…

2 Likes

"Use each Boolean operator no more than once "

You only used the OR operator.

If you are unsure why dsupraja’s answer is correct, keep in mind that parenthesis influence the order of things.

Precedence

1. ( )
2. !
3. &&
4. ||

So you have to work your way from the inner () out. Also if you assume the left most operator will be the “!” then the result of the inner () must evaluate to true. Otherwise the ! can’t flip it to false.

!(true) == false
!(false) == true

BTW, if any reading this gets the “invalid start of type” look at you comparisons. It took me a minute to see I accidentally deleted the left number in the last comparison.

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

2 Likes

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