0
About else-if statement
int age = 25; if(age <= 0) { System.out.println("Error"); } else if(age <= 16) { System.out.println("Too Young"); } else if(age < 100) { System.out.println("Welcome!"); } else { System.out.println("Really?"); for the code given in the course, why don't both 'Welcome' and 'Really' get printed? Why does 'Really' get printed only when input >=100?
1 Respuesta
+ 6
That's because the else block is a fallback when all other (previously specified in if and else if) conditions fail.
So, Really? will only get printed when age is not under 100.