In: Computer Science
(JAVA)
Create a program that prompts the user for an age input. The program defines the age group of the user. Follow the table below to construct the output for your program.
Age | Age Group |
0 | Baby |
1-3 | Toddler |
4-11 | Child |
12-17 | Teenager |
18-21 | Young Adult |
22-64 | Adult |
65+ | Senior |
Negative Number | Invalid Input |
Sample Input Enter an age: 18 Sample Output: You are a young adult.
Sample Input Enter an age: 29 Sample Output: You are an adult.
Sample Input: Enter an age: 10 Sample Output: You are a child.
Sample Input: Enter an age: -10 Sample Output: Invalid Input
import java.util.Scanner;
public class AgeGroup {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter age: ");
int age = sc.nextInt();
if (age < 0) {
System.out.println("Invalid input");
} else if (age == 0) {
System.out.println("You are a baby");
} else if (age >= 1 && age <= 3) {
System.out.println("You are a Toddler");
} else if (age >= 4 && age <= 11) {
System.out.println("You are a Child");
} else if (age >= 12 && age <= 17) {
System.out.println("You are an Teenager");
} else if (age >= 18 && age <= 21) {
System.out.println("You are an Young Adult");
} else if (age >= 22 && age <= 64) {
System.out.println("You are an Adult");
} else if (age >= 65) {
System.out.println("You are an Senior");
}
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me