I'm trying to figure out what's wrong with my code. I can't re-enter into the try block and ask the user to input again.
Commented out are a few things which I've already tried. But nothing has worked. Sometimes will get stuck in infinite loop. Thanks for your help!
public static int integerInput(String prompt,int min) {
int value;
String error, outStr;
Scanner sc = new Scanner(System.in);
value = min - 1;
error = "ERROR value must be above " + min;
outStr = prompt;
do {
try {
System.out.println(outStr);
value = sc.nextInt();
outStr = error + "\n" + prompt;
}
catch (Exception e) {
//value = -1;
//outStr = "ERROR input must be of type int" + "\n" + prompt;
//value = -1;
//value = sc.nextInt();
}
//value = - 1;
}while (value < min);
return value;
}