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.
if you entered the catch block, an exception has been raised.
most surely, the exception is due to the statement
long x=sc.nextLong();
Hence, you cannot use nextLong() to obtain that large a number.
A different way to obtain this number is to use next(). This function returns the next token as a String (in other words, as is). Since every input is a valid String, this function will not fail and will surely give you the next token (the token you failed to obtain using nextLong()).
Java Datatypes
You are viewing a single comment's thread. Return to all comments →
if you entered the catch block, an exception has been raised.
most surely, the exception is due to the statement
Hence, you cannot use nextLong() to obtain that large a number.
A different way to obtain this number is to use next(). This function returns the next token as a String (in other words, as is). Since every input is a valid String, this function will not fail and will surely give you the next token (the token you failed to obtain using nextLong()).