In: Computer Science
Q1: Write a Java program that will display different messages depending on your age.
Your program should ask the user for his/her name and their age in years
and give one or more answers from the following ones below:
Done accordingly. Please comment for further help.
Code:
package Testing;
import java.util.Scanner;
public class AgeMessages {
public static void main(String[] args) {
Scanner input=new
Scanner(System.in);
System.out.print("Please give age
:");
int age=input.nextInt();
if(age<0) {
System.out.println("Invalid Input.");
}else {
if(age<16)
{
System.out.println("You are not allowed to drive
at the moment.");
}
if(age<18)
{
System.out.println("You are not allowed to vote
at the moment.");
}
if(age<25)
{
System.out.println("You are not allowed to rent
a car at the moment.");
}
}
if(age>=25) {
System.out.println("You can do anything that is legal.");
}
input.close();
}
}
Output: