x = input.nextInt();
while (!input.hasNextInt(x)) {
System.out.println("Enter a valid int");
x = input.nextInt();
}
while (x <=0 || x > 3) {
System.out.println("Choose a correct gear number: ");
x = input.nextInt();
}
switch(x) {
case 1:
System.out.println("You're in Gear 1");
break;
case 2:
System.out.println("Gear 2");
break;
case 3:
System.out.println("Gear3");
}
I cannot figure out how to continuously loop asking for an int while x is not an int. I have tried so many things. Everytime I enter a letter or a letter number combination like Q or 23k or 2k etc. I get a mismatch error. I want to be able to check if the user is inputting something he should not in my methods.