Is there a way to check if a user types in a console window in Java?
I want the program to print everything that I type, if I print something, otherwise I will print "Without input".
The tricky part is that I want the program to continue to cycle and print "No input", and then when I type "abc", it immediately displays "abc".
I tried using Scanner for this:
Scanner s = new Scanner(System.in); while(1){ if(s.hasNext()) System.out.println(s.next()); else System.out.println("No input"); }
But when I started it, if I didnโt type anything, the program simply got stuck there without printing โWithout inputโ. In fact, "No Input" was never printed.
source share