private double inputReader(){
Scanner scanner = new Scanner(System.in).useLocale(Locale.US);
while(true){
System.out.println("Input: ");
try {
double value = scanner.nextDouble();
return value;
} catch (InputMismatchException e){
System.out.println("It's not a number");
}
}
}
This method is responsible for scanning input. It throws InputMismatchException when user gives string or something that is not a number. The problem is that when user gives a bad input, it creates a infinite loop resulting in something like this in console:
It's not a number
Input:
It's not a number
Input:
It's not a number
Input:
It's not a number
and so on For me it looks like scanner is reading the same value over and over again, but I don't know how to fix it. I want to make the program asking user for input until he finally gives a correct number.