Java Scanner nextLong() Method
The nextLong() is a Java Scanner class method which is used to scan the next token of the input as a long. There is two different types of Java nextLong() method which can be differentiated depending on its parameter. These are:
This is a Java Scanner class method which is used to scan the next token of the input as a long in the default radix.
nextLong(int radix) Method
This is an inbuilt method of Java Scanner class which is used to scan the next token of the input as a long in the specified radix.
Following is the declaration of nextLong() method:
The nextLong() method returns the long value scanned from the input.
IllegalStateException- This method throws exception if the innvocation is done after the scanner has been closed.
IllegalArgumentException- It throws this exception if the specified radix is out of range.
InputMismatchException- It throws this exception if the next token does not match the Integer regular expression, or is out of range.
Java 1.5 and above
Enter the Number you want: 880 Output value: 388080
Enter Value of a: 12345 Enter Value of x: 123456 Enter Value of b: 1234567 Enter Value of y: 1234 Output: 1223461
Not Found: JavaTpoint.com Found: 13 Not Found: + Found: 13 Not Found: = Not Found: 26.0 Not Found: true Found: 123456789098765432
21845 2869 -9557 -1877 1309
Not Found :11 Not Found :Java Exception in thread "main" java.lang.IllegalArgumentException: radix:2050 at java.base/java.util.Scanner.setRadix(Scanner.java:1368) at java.base/java.util.Scanner.nextLong(Scanner.java:2370) at myPackage.ScannerNextLongExample5.main(ScannerNextLongExample5.java:11)