0
What is the output?
import java.util.Scanner; public class Program { public static void main(String[] args) { int age = 30 if(age < 15){ System.out.println("Child!"); }else if(age >= 15 && age <= 18){ System.out.println("Young!"); }else if(age >= 19 && age < 30){ System.out.println("Adult!"); }else if(age >= 31 && age <= 50){ System.out.println("Mr./Mrs."); }else{ System.out.println("Old!"); } } }
4 Respostas
+ 5
age (30) is not less the 15 so the if statement is not executed.
age is more than 15 but is not less than 30 so the first else if statement is not executed.
age is more than 19 but is not less than 30 so the second else if statement is not executed.
age is not more or equal to 31 so the third if statement is not executed.
So the else statement is executed and "Old!" is outputted.
+ 3
For a correct output you should have included age<=30 instead of age<30
+ 1
You should have just used the code playground
+ 1
Returns "Old!" because no one condition appropriates to 30.