I am trying to read input continuously from the user until the user types quit. I am testing it by just typing \'quit\' but console.hasNext() doesn\'t seem to be returning f
If your Scanner
is declared as System.in
, it will be asking System.in
if there is a next value to be received. The in
class will then wait for the user to input something, then return true.
Reserve hasNext()
for things like files, where the input size is fixed. That way, when Scanner
queries the file, it has a definite hasNext()
.
Instead, I suggest grabbing the next value as a String, then checking if it matches the integer format. If it does, then convert it, otherwise, handle it however you'd like.