I was working on come code for a physics lab to crunch standard deviation for my data (not part of the lab, I don't post my homework on stack overflow) just to make my life a bit easier. I wanted to handle errors that could occur if incorrect data was entered, but whenever I input incorrect data I just get an infinite loop with my error message printing out each iteration. Here is the prolematic code:
// Continue to ask the user for an integer until a correct input is
// given
boolean integerCheck = false;
while (integerCheck == false) {
try {
numberOfPoints = input.nextInt();
integerCheck = true;
} catch(InputMismatchException mismatch) {
System.out.println("Please enter a valid integer.");
}
}
I was wondering if anybody has seen this before, and how they fixed it? Thanks!