Learn Java Programming - Exercise 05x - Nested If Statements

preview_player
Показать описание

Learn how to nest if statements in java to make complex decisions.
Рекомендации по теме
Комментарии
Автор

Nice program, thanks for the explanation

DavidRodriguez-kulo
Автор

public static void main(String[] args) {
Scanner keyboardInput = new Scanner(System.in);

int guess = 1;

System.out.println("How many states are in the United States?");
guess = keyboardInput.nextInt();

if (guess == 50) {
System.out.println("You rock");

} else if (guess == 0) {
System.out.println("Are you kidding me, man!!! Your guess is false!");
} else {
System.out.println("Your answer is false!");
if (guess >= 70)
System.out.println("Your guess is too high!");

else if(guess <= 30) {
System.out.println("Your guess is too low!");

}
}
}
}

hassanel
Автор

import java.util.Scanner;

public class Workspace {

public static void main(String[] args) {

Scanner keyboardInput = new Scanner (System.in);

System.out.println("How many states are in the USA ? ");
int input = keyboardInput.nextInt();

if (input == 51)
System.out.println("it is true");

else {
if (input < 51 && input > 30)
System.out.println("it is low");
else if (input > 1 && input <= 30)
System.out.println("it is too low");
else if (input > 51 && input < 60)
System.out.println("it is high");
else if (input >= 60 && input < 100)
System.out.println("it is too high");
}

System.out.println("\nDo you want guess again ? \n yes or no");
keyboardInput.nextLine(); // consume the newline character
String inputS = keyboardInput.nextLine();

if {

System.out.println("Let's try it again ! How many states are in the USA ?");
int input2 = keyboardInput.nextInt();

if (input2 == 51)
System.out.println("it is true");
else {
if (input < 51)
System.out.println("it is too low");
else {
is too high");
}
}
}

else if {
System.out.println("Okay, may be next time :) ");
}



keyboardInput.close();
}

}

i.s.
visit shbcf.ru