Advertisement
Guest User

JavaIfElseDermot

a guest
Jan 26th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.21 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package javafunwithdermot;
  7.  
  8. import javax.swing.JOptionPane;
  9.  
  10. /**
  11.  *
  12.  * @author Dermot
  13.  */
  14. public class IF_ELSE {
  15.         public static void main(String[] args) {
  16.         try
  17.         {
  18.           int userage = 45;
  19.           if (userage <= 18)
  20.           {
  21.               System.out.println("User is 18 or Younger");
  22.           }
  23.           else if (userage > 18 && userage < 40)
  24.           {
  25.               System.out.println("User is between 19 and 39");
  26.           }
  27.           else if (userage == 45 || userage == 50)
  28.           {
  29.               System.out.println("User is either 45 or 50");
  30.           }
  31.           else
  32.           {
  33.               System.out.println("User is older than 40");
  34.           }
  35.         }
  36.         catch (Exception Ex)
  37.         {
  38.         JOptionPane.showMessageDialog(null,
  39.                 Ex.getClass() + "\n\nCause: " + Ex.getMessage() +
  40.                 "\n\nError came From Line # " + Ex.getStackTrace()[0].getLineNumber(),
  41.                 "ERROR" , JOptionPane.ERROR_MESSAGE);
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement