I need help with a Java Boolean expression exercise


#1



https://www.codecademy.com/courses/learn-java/lessons/conditionals-control-flow/exercises/generalizations-conditionals?action=lesson_resume


This is weird, it might be a bug, but these are the exercises:
1.
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).
2.
Change the Boolean expression in the if statement so that your program will print out the code in the else block instead.

I got the first one right, but I cannot get the second one right and I get the error message:

GeneralizationsB.java:4: error: not a statement
!( 3 >= 3 || (true && true));
^
1 error

I even tried && and all of the Boolean operations you can think of and it still doesn't work. I honestly think this is a bug. I reported it, but I don't know what will happen, hopefully good stuff.

Replace this line with your code. 
public class GeneralizationsB {
	public static void main(String[] args) {

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

	if (2015 > 2016) {

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

  else {

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

		}
	

	int subwayTrain = 9;

		switch (subwayTrain){

			case 1 : System.out.println("This is a South Ferry bound train!");
								break; 
			case 9 : System.out.println("This is a Brooklyn bound train!");
								break;
			case 7 : System.out.println("This is a Queens bound train!");
								break;
			default:
				System.out.println("I'm not sure where that train goes...");
	
		}

	}
}


#2

Hello

I am going to make a suggestion -
The ! at the boolean expression must be //, it is a comment. Do not forget to add it at the back of that comment as well.
That comment must be grey. It must not display any color.

//( 3 >= 3 || (true && true)//;

Hope that helps, let me know if it worked. Also if you feel that your question was solved do not forget to mark it as solved.


#3

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