Question #254382

the average age of obtaining a driver's licence is 18. Write a java program where the user enters his/her age. if the age is greater than or equal to 18, the program must display using JOptionPane the following message, "you are old enough to apply for driver's licence", else display the following message, "you are not old enough to apply for a driver's licence".

Expert's answer

import java.util.Scanner;
import javax.swing.*;  
public class Main
{
	public static void main(String[] args) {
	    JFrame f=new JFrame();
		int age;
		Scanner in=new Scanner(System.in);
		System.out.println("Enter your age: ");
		age=in.nextInt();
		
		if (age>=18){
		    JOptionPane.showMessageDialog(f,"you are old enough to apply for a driver’s licence");  
		}
		else{
		    JOptionPane.showMessageDialog(f,"you are not old enough to apply for a driver’s licence");  
		}
	}
}
LATEST TUTORIALS
APPROVED BY CLIENTS