r/learnjava • u/Super_Good9981 • 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
3
u/BannockBnok Feb 25 '24
Your post doesn't have enough information for us to actually assist you. You've just pasted a small fraction of the code from your IDE without any context or details. "It's not working. What do I do?" is a horrible way to ask others for help. Give us all of your code, and upload it to pastebin with formatting enabled. Then, tell us what you're expecting the code to do and compare it to what it's currently doing.