I'm wondering how do I go about validating this code so the input can only be an int and between a min and max? So far I can only stop the input being less than 1 and whatever maximum is used. But I cant seem to create a scenario where if the user inputs anything other than between the max and min (e.g. "AAA") it loops. I keep getting an Input Mismatch error. Any help would be greatly appreciated!
private static int getUserOption(String prompt, int max) {
int h;
do {
Scanner sc = new Scanner(System.in);
System.out.print(prompt);
h=sc.nextInt();
if(!sc.hasNextInt()) {
System.out.println("Invalid option. Try again!:");
}
} while(h<1 || h>max);
return h;
}