Cannot figure out the riddle lesson


#1



https://www.codecademy.com/en/courses/learn-java/lessons/conditionals-control-flow/exercises/boolean-operators-precedence?action=resume (5. Boolean Operators: Precedence)


The only error I get is to the right and the black box on the right reports false. "Almost! Did you use each Boolean operator no more than one time?"


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

        boolean riddle = ! (false || (true && false));
        System.out.println(false);

    }
}


#2

We are given an incomplete expression to finish by replacing the /**/ in,

boolean riddle = /**/ ( 1 < 8 /**/ (5 > 2 /**/ 3 < 5));

We have three operators, !, && and || and we can only use each once. Start by evaluating the operand expressions.

1 < 8  => true
5 > 2  => true
3 < 5  => true

We are asked to return a false from our completed expression. It would appear all we need to do is make the expression true and then NOT it to result in false.

( true /**/ ( true /**/ true ))

Both of the following will yield true

( true || ( true && true ))

( true && ( true || true ))

So,

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

#3

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