1public class ScannerTest {
2
3 public static void main(String[] args) {
4 Scanner scanner = new Scanner(System.in);
5 try {
6 while (true) {
7 System.out.println("Please input a line");
8 long then = System.currentTimeMillis();
9 String line = scanner.nextLine();
10 long now = System.currentTimeMillis();
11 System.out.printf("Waited %.3fs for user input%n", (now - then) / 1000d);
12 System.out.printf("User input was: %s%n", line);
13 }
14 } catch(IllegalStateException | NoSuchElementException e) {
15 // System.in has been closed
16 System.out.println("System.in was closed; exiting");
17 }
18 }
19}
20