I would like to make the user input a grade only between 0-100 but I would also like for their to be an error message thrown if they enter a letter/word when asked for a numeric grade.
I have tried to make it loop and continually ask the user to input the grade, but when I run the program the exception is not caught and the run-time error still happens.
Can anyone explain why this is happening and guide me on how to fix it, here is my code:
System.out.println("Enter Grade #3 for: " + sArray[x].studentName);
boolean loop = false;
while (!loop) {
try {
int temp3 = kbReader.nextInt();
while (temp3 < 0 || temp3 > 100) {
System.out.println("Error: Please enter a valid grade between 0-100:");
temp3 = kbReader.nextInt();
}
if (temp3 >= 0 && temp3 <= 100) {
sArray[x].grade3 = temp3;
loop = false;
}
} catch (Exception e) {
System.out.println("Error please enter an integer!");
kbReader.reset();
kbReader.nextInt();
}
}