If statement part 2 #46 (Back to the ages)

Code

/// Name: Amir Salehi
/// Period: 7
/// Program Name: Age Messages 3
/// File Name: AgeMessages3.java
/// Date Finished: Oct 29, 2015

import java.util.Scanner;

public class AgeMessages3 {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        String name;
        int age;

        System.out.print("So, what is your name? ");
        name = input.nextLine();

        System.out.print("All right, " + name + ", how old are you? ");
        age = input.nextInt();

        if (age < 16) {
            System.out.println("You can't drive.");
        }
        if (age >= 16 && age < 18) {
            System.out.println("You can drive, but not vote.");
        }
        if (age >= 18 && age < 24) {
            System.out.println("You can vote, but not rent a car.");
        }
        if (age >= 24) {
            System.out.println("You can do pretty much anything.");
        }

    }

}
    

Picture of the output

Assignment 7

Back to Homepage