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.
The reduction in code here comes with a risk. If the input does not contain sufficient data(here int) , the code will fail as nextInt() will throw an Exception. Although input conditions are met in the test cases, in general,its always advised to check hasNextXXX() method before calling respective nextXXX() method to avoid any runtime exceptions or errors. Hope it meakes sense.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Intro to Tutorial Challenges
You are viewing a single comment's thread. Return to all comments →
The reduction in code here comes with a risk. If the input does not contain sufficient data(here int) , the code will fail as nextInt() will throw an Exception. Although input conditions are met in the test cases, in general,its always advised to check hasNextXXX() method before calling respective nextXXX() method to avoid any runtime exceptions or errors. Hope it meakes sense.