Why does this work as both true and false


#1



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


So I actually got it right, but I'm confused why the first part tells me set the boolean variable to true or false, and regardless of which one I choose, I end up with the same result and neither gives me an error. How can I say it's false that 2016 < 2015 and either way it still prints out the same "if" line? Shouldn't it logically make sense to only print that line if the boolean variable is true? How can it be that despite 2016 being greater than 2015, I put it as false, yet the code runs as if it were true... I think?


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

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

	if(2016 < 2015) {

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

		}else {

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

		}


#2

If you read your code, tricky is only mentioned while it's defined, it isn't used anywhere else and will therefore have no effect. Perhaps you were supposed to do something slightly different


#3

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