0
Can someone tell what's wrong with this code?
//Remove the given age below and enter your age. public class Program { public static void main(String[] args) { int age=19; if(age == 16) if(age == 17) { System.out.println("Get your provisional license"); if(age < 15){ System.out.println("Too young!"); if(age == 15){ System.out.println("Get learner's license"); if(age >= 18){ System.out.println("Congrats! Get driver's license."); } } } } } }
2 Respostas
+ 2
age=19 and if condition if(age==16) becomes false so it directly goes to else part but you dont have else. No other statements gets executed because all next statements is in
if(age==16)
{
here..
}
Hence there no output..
Learn about if-else structure for more understandings...
0
// instead use
if ()
...
else if ()
...
else if ()