How would I take a simple if-else statement using a Scanner for keyboard input, compare an integer against an argument and re prompt the user to input the integer again if it is not the desired result? Here is what I have, I think this should be fairly easy but I'm only learning;
public static void main(String[] args) {
Scanner myInt = new Scanner(System.in);
System.out.println("Enter a number between 1 and 10");
int choice = myInt.nextInt();
if (choice <= 10) {
System.out.println("acceptable");
} else {
System.out.println("unacceptable");
System.out.println("Enter a number between 1 and 10");
}
}
}
Any tips on how I should approach this?
Thanks!
choicemust be>= 1as well. Currently you would accept0(or any negative value).