11.Generalizations. Boolean


#1

My problem

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


#2

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

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

#3

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


#4

It is actually false


#5

Yeah. I just solved it. Thanks anyway


#6

How did you solve it


#7

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?


#8

Yes it does! Absolutely correct


#10

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.


#11

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


#12

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


#13

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


#14

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