In: Computer Science
Write a Java application that prompts the user for an age. If the age entered is greater or equal to 65, display the statement "Age is greater than or equal to 65"; otherwise display the message "Age is less than 65". If the age entered is less than 18; display the statement "This person is a minor"; otherwise display the message "This person can legally vote. Do not create a class for this application. The code can be created in the main driver program.
Java Code:
import java.util.Scanner;
class Main {
public static void main(String[] args) {
int age;
Scanner sc = new Scanner(System.in);
System.out.print("Enter age: ");
age = sc.nextInt();
if(age >= 65)
{
System.out.print("Age is greater than or equal to 65");
}
else if(age < 65)
{
System.out.println("Age is less than 65");
}
else if( age < 18)
{
System.out.println("This person is a minor");
}
else{
System.out.println("This person can legally vote");
}
}
}
Screenshots: