Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("What is your age?");
- while(scanner.hasNext()) {
- final String supposedAge = scanner.next();
- int age;
- {
- try {
- age = Integer.valueOf(supposedAge);
- } catch (Exception ex) {
- System.out.println("You must supply an integer for your age.");
- System.exit(0);
- return;
- }
- if(age > 120) {
- System.out.println("You must supply a valid age.");
- System.exit(0);
- return;
- }
- if(age == 0) age++;
- }
- System.out.println("Your age is " + age + ".");
- if(age <= 2) {
- System.out.println("You are a newborn.");
- } else if(age < 6 && age > 2 ) {
- System.out.println("You are a toddler");
- } else if(age > 6 && age < 13) {
- System.out.println("You are a child");
- } else if(age >= 13 && age < 18) {
- System.out.println("You are a teenager.");
- } else {
- System.out.println("You are an adult.");
- }
- System.exit(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement