Replace s.next()
to s.nextLine()
and you will get the desired result.
-
next()
finds and returns the next complete token from this scanner. A complete token is preceded and followed by input that matches the delimiter pattern. -
nextLine()
returns the rest of the current line, excluding any line separator at the end. The position is set to the beginning of the next line.
-> "123456 78"
s.next().length() -> "123456".length() -> 6
s.nextLine().length() -> "123456 78".length() -> 9
1
solved Java (Length of an input)