Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java wait for user input

public class ScannerTest {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        try {
            while (true) {
                System.out.println("Please input a line");
                long then = System.currentTimeMillis();
                String line = scanner.nextLine();
                long now = System.currentTimeMillis();
                System.out.printf("Waited %.3fs for user input%n", (now - then) / 1000d);
                System.out.printf("User input was: %s%n", line);
            }
        } catch(IllegalStateException | NoSuchElementException e) {
            // System.in has been closed
            System.out.println("System.in was closed; exiting");
        }
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: setbackground color hexadecimal android 
Java :: check folder for files java 
Java :: java printf tab 
Java :: display in java 
Java :: java iterate hashmap 
Java :: initialize hashmap with values 
Java :: how to go to next iteration of while loop java 
Java :: is a and has a relationship in java 
Java :: palindrome find in java 
Java :: java new char array 
Java :: enum java 
Java :: flink prometheus alert on failed jobs 
Java :: insertion sort in java 
Java :: input long in java 
Java :: apache commons collections android dependency 
Java :: set spring context 
Java :: get last string separated by / 
Java :: download File java from website 
Java :: Java Longest String In String Array 
Java :: java date add hours 
Java :: Java do...while loop 
Java :: recursion in java 
Java :: quarkus skip test 
Java :: java netbeans textfield only numbers 
Java :: how to create folder java 
Java :: iterate list in java 
Java :: File Appender log4j2.properties spring 
Java :: Caused by: java.io.EOFException: SSL peer shut down incorrectly 
Java :: do you need java installed for kafka 
Java :: boolean in java 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =