int memberChoice;
boolean accountLoop = true;
while (accountLoop) {
try {
System.out.println("Would you like to be a... \n1.Basic Member or \n2.Premium member");
memberChoice = input.nextInt();
if (memberChoice == 1 || memberChoice == 2) {
accountLoop = false;
}
if (memberChoice < 1 || memberChoice > 2) {
System.out.println("Please choose either 1 or 2");
}
System.out.println();
} catch (InputMismatchException e) {
System.out.println("Invalid input");
}
}
Whenever I type a string it should say invalid input go back to the beginning of the loop and direct me to input a number again. Instead it gives me an infinite loop. I feel like its something really small but I've been at this for 5 hours and can't figure it out. Any suggestions?