Originally posted by Daisy Lakhanpal:
But 3l is a long value. So hasNextLong() is still true.Why does loop end..
May be its really very easy question. But i just did not get it.
You have to distinguish the parsers. Just because the
Java compiler understands the 3L to mean a long value, doesn't mean the Scanner parser does. Notice that it also doesn't understand hexicimal, octal, or expressions -- the nextLong() method is just a dumb numeric parser.
[Don't want to belittle the Scanner class, as it does have methods that support radixes. The point of the argument is that you need to understand what the Scanner class is looking for -- not what the Java compiler is looking for.]
Henry
[ December 13, 2008: Message edited by: Henry Wong ]