Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import javax.swing.JOptionPane;
- public class AgeIO {
- public static void main(String[] args){
- Scanner input = new Scanner(System.in);
- int age1 = 0;
- double age2i = 0;
- //System.out.println("What is your age?");
- try {
- System.out.println("What is your age?");
- age1 = Integer.parseInt(input.next());
- }
- catch(NumberFormatException e) {
- System.out.println(e.getMessage() + " is not an integer.");
- }
- if(age1 < 0)
- throw new IllegalArgumentException("The age does not compute.");
- System.out.println("Your age is " + age1 + ".");
- String age2 = JOptionPane.showInputDialog(null, "What is your age again?");
- try {
- age2i = Double.parseDouble(age2);
- }
- catch(NumberFormatException e){
- JOptionPane.showMessageDialog(null, e.getMessage() + "is not an integer.");
- }
- JOptionPane.showMessageDialog(null, "My age is " + age2i);
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement