There are a few issues here. First s.next()
grabs a whitespace-delimited token and returns the entire token as a single string. Second, because Scanner
uses whitespace as a delimiter, it will never return \r
, it will just skip it and read the next token.
Why not use s.readLine()
and simply echo the whole line? While it won't process characters as they are entered (Scanner
can't really do this, it always buffers lines), it will be closer to your described requirement.