Question 11- Conditionals and Conditions Flow


#1

How do you solve the following question?
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).

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

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

if(2015 < 2016) {

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

	}else {

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

	}

#2

This is correct - this expression 3 &gt;= 3 && !(true || true) ); is really false.


#3

thank you!
many thanks


#4

WHAAAAAAT? im soooooo clueless


#5

what did you do to get it right?


#6

3 >= 3 - this is true, because 3 is equal to 3
!(true || true) - this is false, because the expression in the brackets is true and there is "!" before the brackets

When we use the && operator to 3 >= 3 and !(true || true) we have true && false which is false.

Then the instructions say to set this value to tricky. That's all : )


#7

i knw beginning to be annoying bt can u type what u wrote to get the right results?
this is now getting to that i dont get what they are asking me to do


#8

@forch:

Without giving you code, let's see if we can get you understanding this. The goal here is to learn, so don't give up! Let's stretch your brain a bit.

You need to use non-code related logic skills to evaluate for yourself the answer to 3 >= 3 && !(true || true));

In plain English, the above snippet means:

"Three IS GREATER THAN OR EQUAL TO three AND THE INVERSE OF THE GROUP true OR true."

Using logic, we can see the sentence as a whole is false.

Breaking it up:
1. Three IS GREATER THAN OR EQUAL TO three: this is true!
2. THE INVERSE OF THE GROUP true OR true: this is false!

When comparing two things and one of the two is false, then the entire thing can never be true.

Do you see or can you infer as to why that is?

The instructions of this exercise ask you to simply evaluate in your head whether the expression as a whole is true or false, which, as explain, it is clearly false. Therefore, either set tricky to the expression itself or to the primitive boolean literal false.

Do you understand? :smile:


#9

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

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

if(2015 < 2016) {

.... what did i do wrong? its not running


#10

You need an = assignment operator.

boolean tricky **=** (3 >= 3 && (true || true))


#11

wooooooooow i was way outer space,


#12

Honestly, I'm super confused with this whole thing. I don't really know what it's asking me to do :confused:


#13

// first you must evaluate the expression on the next line ( it will be true or false )
// ( 3 >= 3 && !(true || true) )

// then put the answer after the = sign on this next line:
boolean tricky =

Setting Boolean 'tricky'
#14

OK... This makes sense. It was basically saying type two statements that may or may not be true! like true==false or 3>=2 or whatever. Alright I got it.


#15

great yaar you solved my problem


#17

Hello from Serbia, can you please help me?...here is my code

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

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

if(!(2015 < 2016)) {

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

	}else {

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

	}

Lets move further on this exercises, although Ive done first part of exercise like you said, I get this message
"GeneralizationsB.java:4: error: not a statement
(3 >= 3 && !(true || true));
^
1 error"

In second part of exercise I should change something in IF statement to escape true answer and print false (else statement), right?
So I try several things....first I wrote
if(2015 > 2016).....then
if(2015 < 2014).....then
if(!(2015 < 2016)).....
and everytime I can not pass

What is wrong with my code?


#18

in the same exercise, part three, we should put number 5 instead of th 9, right?


#19

hey just figured it out put the // back in to the beginning.
just undo the first half of step one


#20

Is there any other way to put another equation in to solve it, i'm not seeing where you all got the equation that you are using and the actual digits that you are using to solve this exercise. I would like to solve it with a different equation if possible. If that is not possible, where did you get this equation from? I don't see this equation set up on the exercise. Please respond.


#21

2 posts were split to a new topic: How do you solve problem 11/12?