Write a snippet of Java code not an entire program to pop up

Write a snippet of Java code (not an entire program) to pop up an option pane (use JOptionPane) asking the user for his or her age. If the user types a number less than 16, respond with a message box saying that he or she is too young to drive. Otherwise, tell the user that they are old enough to drive.

Solution

import javax.swing.JOptionPane;

public class InputBoxes {
   public static void main(String args[])
   {
       String Age=JOptionPane.showInputDialog(\"Please enter your age\");
       int age = Integer.parseInt(Age);
       if(age<16)
       {
           String message=\"You are too young to drive\";
           JOptionPane.showMessageDialog(null, message);
       }
       else
       {
           String message=\"You are old enough to drive\";
           JOptionPane.showMessageDialog(null, message);
       }
   }
}

Write a snippet of Java code (not an entire program) to pop up an option pane (use JOptionPane) asking the user for his or her age. If the user types a number l

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site