You mean, have the scanner reject a blank line? From the command line?
There's no way to prevent the blank line appearing in the command line window. A Java application can not control this behavior. However, if a user enters a blank line, you can just treat the line (which would be an empty string) as invalid input the same way you would treat other invalid input.
If you retain the default delimiter, that is only a problem if you use the findInLine() (beware: overloaded) or nextLine() methods. If you use nextInt() or similar, the line end sequences count as part of the delimiter, so the Scanner object ignores them.
Didn't I show you a utility class on Friday? Remember that System.in should remain open for ever, so it always has a next line implicitly.You cna insert a method like this:-Java11+ users may prefer to use the strip() method rather than trim().
And why didn't I use System.out.printf on Friday?
My, my, aren't you a big fella. Here, have a tiny ad:
global solutions you can do in your home or backyard