Assignemnt #34 How Old Are You
Code
Name: Iaroslav Titov
Period: 7
Project Name: HowOldRU
File Name: HowOldRU.java
Date: 10/2/2015
import java.util.Scanner;
import java.util.InputMismatchException;
public class HowOldRU
{
public static void main (String[] args)
{
Scanner keyboard = new Scanner(System.in);
String name;
int age;
try
{
System.out.print( "Input your name " );
name = keyboard.next();
System.out.println();
System.out.print( "Hi, " + name + "! Input your age " );
age = keyboard.nextInt();
System.out.println();
if (age < 16) System.out.println(name+", you can't drive!!!");
if (age < 18) System.out.println(name+", you can't vote!!!");
if (age < 25) System.out.println(name+", you can't rent a car!!!");
else System.out.println(name+", you can do anything that is not illegal!!!");
}
catch (InputMismatchException e)
{
System.out.println( "WRONG INPUT!!!" );
}
}
}
Picture of the output