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.
No, you would actually get an exception. If after the nextDouble() you try to get another one It will try to convert the nextline into a double, causing an inputmismatchexception.
Basic idea about using getInt(), getDouble(), etc would be to ensure the data you are getting is of the expected type as soon as possible.
If you are less rigid and use something like Object firstinput = sc.next(); there may be some typo on the input, such as '456.o5 ' -> This would cause that 'firstinput' is no longer a double, causing later on an exception if you try to multiple or divide by it.
If you get the error while you are reading the input, you will have less work to do while debugging
Hope it helps to clarify (corrections are welcome)
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 →
No, you would actually get an exception. If after the nextDouble() you try to get another one It will try to convert the nextline into a double, causing an inputmismatchexception.
Basic idea about using getInt(), getDouble(), etc would be to ensure the data you are getting is of the expected type as soon as possible.
If you are less rigid and use something like Object firstinput = sc.next(); there may be some typo on the input, such as '456.o5 ' -> This would cause that 'firstinput' is no longer a double, causing later on an exception if you try to multiple or divide by it.
If you get the error while you are reading the input, you will have less work to do while debugging
Hope it helps to clarify (corrections are welcome)