Boolean predence! i do not understand clearly, please help


#1

I did not really understand clearly how boolean precedence works, could someone please help.
exercise 11 has been bugging how i should write the code.


#2

Hi. Can you post the code you have attempted with?


#3

boolean tricky = !( 3 >= 3 && (true || true) );

System.out.println(tricky);


#4

1.
Use the precedence rules to help you evaluate the Boolean expression in the single line comment above the tricky variable.

Then, set the boolean variable tricky equal to the result (either true or false).

First, you don't actually have to do anything to the comment you are just evaluating it with the statement you will code below it. So you can put the ( 3 >= 3 && (true || true) ) back behind //
Secondly, All you have to do is do exactly what the instructions say set boolean var tricky equal to either true or false. So this might look like this:

boolean tricky = false;

If you need help on the rest of the lesson then just ask away! :smiley: And of course if that doesn't help then shout back lol


#5

Thanks, I'm getting the hang of this now


#6

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

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

}

}
Answer is false
but how this is possoble


#7

So lets start with like this

(1<8= As 1 is less than 8 it will print as True)
(5>2 =As 5 is less than 8 it will print as True)
(3<5 =As 3 is less than 8 it will print as True)

So we have now

!(True || (true && true))

Which will become now as

!(True || True)

Which will become now as
!(True)

Nd will print as False..


#8

No it's not.It showing false.


#9

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