r/learnjava • • Feb 25 '24

Java if else statement

System.out.print("40: ");

int age = scanner.nextInt();

if (age < 0 || age > 120) {

System.out.println("Invalid age");

} else if (age <= 12) {

System.out.println("Child");

} else if (age <= 19) {

System.out.println("Teenager");

} else if (age <= 64) {

System.out.println("Adult");

} else {

System.out.println("Senior Citizen");

}

I wanted to print a specific result but it wasn't coming up, what errors am i making

0 Upvotes

25 comments sorted by

View all comments

0

u/National-Apartment20 Feb 25 '24

You are not using scanner here. For simplicity try int age =40;