11.Generalizations. Boolean

My problem

I know that it’s true but I don’t know how to alter the first part.

Nest a if statement on the first conditon. So like this:

if(3>-3 &&!(true||true)){
boolean tricky = true;
1 Like

The exercise is expecting you to leave the expression as a comment.

1 Like

It is actually false

1 Like

Yeah. I just solved it. Thanks anyway

How did you solve it

I realised it after i tried true and false.

I dont know really why, but i guess it has to do with the order (forgot already how it’s called) in which the functions operate.
The or-operation is one of the expressions but the and-operation doesn’t know it because it operates before the or-operation and has no input at that moment.

So, in the end, without input it is a “false” and therefore: true && false = false — correct?

1 Like

Yes it does! Absolutely correct

It’s not true…

This is how I broke it down…to get to the answer

// ( 3 >= 3 && !(true || true) ) // true or true = true
// 3 >= 3 && !(true) // not true = false
// 3 >= 3 && false // 3 >= 3 = true
// true && false // = false
// answer: tricky = false; because true && false evaluate to false in a truth table.

Go look at a truth table to get the answer.

1 Like

What i did was paste the commented string after the boolean tricky so i got:

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

This way you don’t have to think about it

There is another tricky one:

if(2015 > 2016) {

		System.out.println("Stuck in the past...");

	} else {

		System.out.println("Upgraded to the future!");

the print out is “Upgraded to the future!” be careful on the top to disable first exercise boolean tricky. Could figure out this out but finally

thank you for your help guys .without your discussion i would’t be able to solve the problem.

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