Assignemnt #34: How Old Are You?
Code
/// Name: Kelsey Lieberman
/// Period 5
/// Program Name: HowOldAreYou
/// File Name: HowOldAreYou.java
/// Date Finished: 10/14/2015
import java.util.Scanner;
public class HowOldAreYou
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
String name;
int age;
System.out.print("What's your name? ");
name = keyboard.next();
System.out.print("How old are you, " + name + "? ");
age = keyboard.nextInt();
if (age < 16)
{
System.out.println("You can't drive!");
}
if (age > 16)
{
System.out.println("You can drive!");
}
if (age < 18)
{
System.out.println("You can't vote!");
}
if (age > 18)
{
System.out.println("You can vote!");
}
if (age > 25)
{
System.out.println("You can rent a car and do anything that is legal!");
}
if (age < 25)
{
System.out.println("You can rent a car!");
}
}
}
Picture of the output