daniel_g
12-01-2006, 02:49 AM
Sorry for asking this simple question, but I've got a bad cold today, and can't think properly. I probably even have an example on how to solve that problem somewhere on my computer, but I can't keep staring at the monitor any longer.
I'm trying to check the user's input is a double or not. So far this is what I've got:
while(bool == 0){
try{
System.out.println("Enter Rate of Fire: ");
CSrate = scan.nextDouble();
bool = 1;
}
catch(Exception e){
System.out.println("Not a number");
}//end catch
}//end while
If I run it one time, and hit, for example, "k" instead of a double, the program will just loop forever asking for the rate of fire, and telling me is "not a number" without allowing user to input the rate of fire again. Maybe try - catch inside a while loop doesn't quite work the way I'm hoping it does.
I'm going to go rest for a couple hours, and hopefully I'll have a reply by the time I wake up, or maybe my mind will be clrear enough to figure it out my self.
I'm trying to check the user's input is a double or not. So far this is what I've got:
while(bool == 0){
try{
System.out.println("Enter Rate of Fire: ");
CSrate = scan.nextDouble();
bool = 1;
}
catch(Exception e){
System.out.println("Not a number");
}//end catch
}//end while
If I run it one time, and hit, for example, "k" instead of a double, the program will just loop forever asking for the rate of fire, and telling me is "not a number" without allowing user to input the rate of fire again. Maybe try - catch inside a while loop doesn't quite work the way I'm hoping it does.
I'm going to go rest for a couple hours, and hopefully I'll have a reply by the time I wake up, or maybe my mind will be clrear enough to figure it out my self.