I would like to have the user input a line of text as long as x
is not equal to the value of numOfContestans
. When I run the code, I get an InputMismatchException
. Does anyone have an idea on how to solve this error?
try {
int numOfContestants = scan.nextInt();
int problems = scan.nextInt();
scan.nextLine();
int x = 0;
while (x != numOfContestants) {
String input = scan.nextLine();
x++;
}
System.out.println(problems);
} catch(InputMismatchException e) {
System.out.println("Something went wrong");
}