What am i doing wrong? 5Boolean Operations: Precedence

My code:

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

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

	// ( !true || (false && true) )
	boolean puzzle = ( !true || (false && true) );
	System.out.println(puzzle);
	
	}
}
  1. Set the boolean variable puzzle equal to the Boolean result of the single line comment directly above it.

Error: Try again. The variable puzzle should equal either true or false.

Instructions are sorta unclear, you’re actually supposed to set puzzle equal to true or false based on the commented expression. ( !true || (false && true)) == false, so puzzle should equal false.

The required use of boolean operators to be as mentioned below -

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

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

}

}

1 Like

i did this it showed this error. Did u use boolean operators no more than once each.

leave space from relational operator to bracket or number

my code print out false as instruction, and I use each boolean operator once but it still show error “Almost! Did you use each Boolean operator no more than one time?”

1 Like