Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. import javax.swing.JOptionPane;
  4.  
  5. public class AgeIO {
  6.  
  7. public static void main(String[] args){
  8.  
  9. Scanner input = new Scanner(System.in);
  10. int age1 = 0;
  11. double age2i = 0;
  12.  
  13. //System.out.println("What is your age?");
  14.  
  15. try {
  16. System.out.println("What is your age?");
  17. age1 = Integer.parseInt(input.next());
  18. }
  19. catch(NumberFormatException e) {
  20. System.out.println(e.getMessage() + " is not an integer.");
  21. }
  22.  
  23. if(age1 < 0)
  24. throw new IllegalArgumentException("The age does not compute.");
  25.  
  26. System.out.println("Your age is " + age1 + ".");
  27.  
  28. String age2 = JOptionPane.showInputDialog(null, "What is your age again?");
  29.  
  30. try {
  31. age2i = Double.parseDouble(age2);
  32. }
  33. catch(NumberFormatException e){
  34. JOptionPane.showMessageDialog(null, e.getMessage() + "is not an integer.");
  35. }
  36.  
  37. JOptionPane.showMessageDialog(null, "My age is " + age2i);
  38. System.exit(0);
  39. }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement