Assignemnt #37
Code
/// Name: Daniel Nguyen
/// Period: 6
/// Program Name: NameIfElse Program
/// File Name: NameIfElse.java
/// Date Finished: 9/9/2015
import java.util.Scanner ;
public class NameIfElse
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
String name;
int age;
System.out.print( "Hey, what's your name? (Sorry, I keep forgetting.) " );
name = keyboard.next();
System.out.print( "Ok, " + name + " how old are you? " );
age = keyboard.nextInt();
if ( age < 16 ) {
System.out.println( "You can't drive." ); }
else if ( age < 18 && age > 15 ) {
System.out.println( "You can drive but not vote." ); }
else if ( age < 25 && age > 17 ) {
System.out.println( "You can vote but not rent a car." ); }
else if ( age >= 25 ) {
System.out.println( "You can pretty much do anything." ); }
}
}
Picture of the output