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 cant figure out how to continuously loop asking for an int while x doesnt = an int. Ive tried so many thing. 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 use is inputting something they shouldnt in my methods.
Aucun commentaire:
Enregistrer un commentaire