Restart input if Illegal argument?

From: bunallo (nmnm_at_alala.com)
Date: 01/25/05

  • Next message: klynn47_at_comcast.net: "Re: Restart input if Illegal argument?"
    Date: Tue, 25 Jan 2005 20:56:43 +0100
    
    

    Is it possible to jumb back to intput lines and run them until the user has
    typed a positive number?

    import javax.swing.*;

    class Test34{
      public static void main(String[] args){

        try{

        int a = new Integer(JOptionPane.showInputDialog("Enter a
    number")).intValue();
        int b = new Integer(JOptionPane.showInputDialog("Enter a
    number")).intValue();

        if(a < 0 || b < 0 ){throw new IllegalArgumentException();}

        JOptionPane.showMessageDialog(null, a + " + " + b + " = " + (a + b));

        }
        catch(IllegalArgumentException e){
          JOptionPane.showMessageDialog(null, "Number has to a positive
    integer");
        }
      }
    }


  • Next message: klynn47_at_comcast.net: "Re: Restart input if Illegal argument?"

    Relevant Pages