Is there a way to check if the user is typing in the console window in Java?
I want the program print whatever I type if I type something, otherwise print out "No input".
The tricky part is I want the program keep looping and printing out "No input", and then when I type "abc", it would immediately print out "abc".
I tried to use Scanner to do this as:
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 ran it, if I did not type anything, the program just stuck there without printing "No input". Actually, "No input" was never printed.