I am using a scanner class to enter user input from the command line (string only) as an alternative to the previous question .
Everything seems to be working fine, except that empty lines are not caught, just like the second condition. For example, when I press enter, this should be written as an empty string, and the second condition should be true. However, a new empty line is displayed on the console every time, while the entire console "scrolls" up if I continue to enter enter, and not in the conditional logic.
Is there a correct way to catch empty input from the command line using a scanner? (someone hit, just type or press spacebar several times and then enter)
Thanks for any advice.
Machine aMachine = new Machine();
String select;
Scanner br = new Scanner(System.in);
while(aMachine.stillInUse()){
select = br.next();
if (Pattern.matches("[rqRQ1-6]", select.trim())) {
aMachine.getCommand(select.trim().toUpperCase()).execute(aMachine);
}
else if(select.trim().isEmpty()){
aMachine.getStatus();
else {
System.out.println(aMachine.badCommand()+select);
aMachine.getStatus();
}
}