i have this piece of code. I wanted to return to the beginning of loop and ask for user input again. However, it always loops without stopping to ask for input. What is wron
This works fine:
import java.util.InputMismatchException;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int choice;
while(true){
try {
choice = input.nextInt();
System.out.println("Your choice: " + choice);
} catch (InputMismatchException e){
e.printStackTrace();
}
}
}
}