We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
A bit confused at first but now I know.
Here's what's happening step by step:
scan.nextInt() reads "42" and leaves the newline character in the buffer.
scan.nextDouble() then reads "3.1415", but it first skips any leading whitespace (including the newline left by nextInt()). It again leaves the newline after "3.1415" in the buffer.
If we were to use nextLine() immediately after nextDouble(), it would read this empty line (just the newline character).
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Stdin and Stdout II
You are viewing a single comment's thread. Return to all comments →
A bit confused at first but now I know. Here's what's happening step by step: