Restart input if Illegal argument?
From: bunallo (nmnm_at_alala.com)
Date: 01/25/05
- Previous message: Sergio: "Re: Unicode data from Mysql"
- Next in thread: klynn47_at_comcast.net: "Re: Restart input if Illegal argument?"
- Reply: klynn47_at_comcast.net: "Re: Restart input if Illegal argument?"
- Reply: Steve W. Jackson: "Re: Restart input if Illegal argument?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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");
}
}
}
- Previous message: Sergio: "Re: Unicode data from Mysql"
- Next in thread: klynn47_at_comcast.net: "Re: Restart input if Illegal argument?"
- Reply: klynn47_at_comcast.net: "Re: Restart input if Illegal argument?"
- Reply: Steve W. Jackson: "Re: Restart input if Illegal argument?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|