I am trying to make sure the user can only enter numbers 0 - 100, can any of you Java geniuses give me a hint. My regex matches the inputs I want, but when I enter a '9' I encounter an error when I cast the string to a double. Actually the input value is never assigned to the perc variable, but only when the input is a single digit. Here' s the piece of code that's giving me this headache:
while(!in.hasNext("[0-9]")){
try {
perc = in.next("[0-9]{1,2}|100");
break;
} catch (InputMismatchException e) {
System.out.println("Bad Input - Try Again");
perc = in.next();
}
}
dblPerc = Double.parseDouble(perc);
And here's the error:
Exception in thread "main" java.lang.NumberFormatException: empty String
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:994)
at java.lang.Double.parseDouble(Double.java:510)
at applicant_database.View.showInput(View.java:46)
at applicant_database.View.main(View.java:101)