7. If-Else Statement


#1

I don't know how to do this!

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

	if (7 <= 7) {

		System.out.println("Try again...");

	} else {

		System.out.println("Success!");

	}
	
}

}

the instructions are: 1.
The if/else statement in the code editor currently prints out the code in the if block. Modify the if statement's Boolean expression so that the code in the else block gets executed and prints to the console.


#2

Hey @wendybxiong. First of all when you ask a question just quickly organize it, by just selecting all your code and hiting CTRL + K. Secondly your problem is the instruction says make sure the else statement gets executed. And in your if statement it says

if(7<=7)

Meaning if 7 is less than or equal to. And we know 7 is equal to 7 so it will execute the if statement! We dont want that! We want the else statement to execute. So just change it to if 7 is less than 7 whitch is not true.

Your Error Part Code:

if (7 <= 7) {

Correct Code:

  if (7 < 7) {

Hope it helped! If it didnt pls reply saying so! Java is the best!


#3

A post was split to a new topic: It shows output as "Success" but still the platform shows error


#4