So I am trying to deal with the possible exception of a user entering a double when my scanner is expecting integral input:
boolean go = true;
do {
System.out.print("Please enter one grade from 0 - 100. To end input, enter a
negative integral value.\n");
try {
int myInt = scanner.nextInt();
.
.
.
}
catch (InputMismatchException e) {
System.out.println("Oops!! Please enter only integral numbers");
}
while (go);
This works for non-numerical input (i.e. a letter), but not if I enter, say 3.14 or another ASCII symbol like -. In that case, the lines below repeat until I kill the program.
Please enter one grade from 0 - 100. To end input, enter a negative integral value.
Oops!! Please enter only integral numbers.
Any ideas? :D
Reply: I am using System.in, and java 6.