Java scanner with integers, stop this loop with empty line
Solution 1:
You could use in.nextLine()
instead of in.nextInt()
, and then use the isEmpty()
function to check if it is empty and Integer.parseInt()
to convert it back to an int. You can do it more efficiently but this should suffice
int num = 0;
String input = in.nextLine();
if(input.isEmpty()){
auth = false;
}
else{
num = Integer.parseInt(input);
System.out.println(num);
}