desired result not obtained after running code | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

desired result not obtained after running code

Public class myclass { public static void main(String[] args) { int age = 101; if(age > 0) { if(age > 16) { if(age < 60) {if (age<100) { System.out.println("Welcome!"); } else { System.out.println("too old");}} else { System.out.println("old"); }} else { System.out.println("Too Young"); } } else { System.out.println("Error"); } } } here as the age + 101 and greater than 100, I think the result should be "too old" but what I am getting is "old".Can anyone explain me why this happens

2nd Feb 2017, 5:59 PM
Nihal Mazhar U V
2 Answers
0
because it is not satisfying the 3rd condition,,, it is age<60..false...then it will go to else part
2nd Feb 2017, 6:10 PM
Somnath Ghosh
Somnath Ghosh - avatar
0
Its not satisfying the third and fourth condition so it will move to the else part but in the else part why it is giving output as "old" instead of "too old"?
2nd Feb 2017, 7:05 PM
Nihal Mazhar U V