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.
It works to some extent, but not really. It doesn't pass the first test case, but it passes the second.
Why doesn't nextFloat() pass the first test case? Simply because it doesn't generatre the exact expected output. The expected output is (3.1415), and it generates (3.1414999961853027).
Reason? Simply because double is of a bigger size (8 bytes - up to 15 significant decimal digits), while float is smaller (4 bytes - up to 6-7 significant decimal digits).
Java Stdin and Stdout II
You are viewing a single comment's thread. Return to all comments →
It works to some extent, but not really. It doesn't pass the first test case, but it passes the second.
Why doesn't nextFloat() pass the first test case? Simply because it doesn't generatre the exact expected output. The expected output is (3.1415), and it generates (3.1414999961853027).
Reason? Simply because double is of a bigger size (8 bytes - up to 15 significant decimal digits), while float is smaller (4 bytes - up to 6-7 significant decimal digits).
Reference (I hope this doesn't violate HackerRank policies): http://bit.ly/2DqTF9W