Answer the question
In order to leave comments, you need to log in
How to reuse Scanner(System.in) if EOF arrives?
int var;
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext() && scanner.hasNextLine()) {
System.out.printf("Enter an integer: ");
try {
var = scanner.nextInt();
} catch (InputMismatchException e) {
scanner.nextLine();
} catch (NoSuchElementException e) {
// TODO: how to handle CTRL+D?
}
}
scanner.close();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question