I am doing a basic java console application and I want to check if the user provided any input before pressing enter. I’m using the Scanner class to get the input. Right now all I get is that the application just waits for input whenever I press enter without typing in anything.
Share
You can go in a loop that waits for enter. If the user presses enter, check for input, if no input is provided, continue the loop. If input was provided, break from the loop.
If you want the mechanism to be non-locking, you need a separate thread.