Problem:
Write a program that takes the name and the age of the user. The program should check the age of the user and then prints out if the person can get his driver license or not.
If the age is under 18 then you should print “ ……. Too young to get his/her driving license”If the age is greater than or equal to 18 then the program should print “……. can have his/her Driving License”.
The program should look as follows:
Enter Name:
Talal
Enter Age:
16
Talal is too young to get his driving License
Solution:
/** * @(#)Problem3.java * * * @author George Chalhoub * @version 1.00 2012/10/16 */ import java.util.Scanner; public class Problem3 { public static void main(String args[]) { Scanner input=new Scanner(System.in); System.out.print("Enter name:"); String name=input.nextLine(); System.out.print("Enter Age:"); int age=input.nextInt(); if (age<18) System.out.print(name+" is too young to get his/her driving license"); else System.out.print(name+" can get his/her driver license"); } }
No comments :
Post a Comment