Write a Java program that asks the user to enter a person’s age. Then the program should display text indicating whether the person is an infant, a toddler, a child, a teenager, an adult, or a senior. It should display it just like this: “This person’s age category: x”, where x is the person’s age category based on the following guidelines:
If less than 1 year old, the person is an infant.
If at least 1 year old but younger than 3, the person is a toddler.
If at least 3 years old but younger than 13, the person is a child.
If at least 13 years old but younger than 18, the person is a teenager.
If at least 18 years old but younger than 65, the person is an adult.
If 65 or older, the person is a senior.
import java.util.Scanner; public class PersonAgeCategory { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("Enter person's age: "); int age = in.nextInt(); String category; if (age < 1) { category = "infant"; } else if (age < 3) { category = "toddler"; } else if (age < 13) { category = "child"; } else if (age < 18) { category = "teenager"; } else if (age < 65) { category = "adult"; } else { category = "senior"; } System.out.println("This person's age category: " + category); } }
Get Answers For Free
Most questions answered within 1 hours.