Java Scanner nextLong() MethodThe 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:
nextLong() MethodThis 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) MethodThis 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. SyntaxFollowing is the declaration of nextLong() method: Parameter
ReturnsThe nextLong() method returns the long value scanned from the input. ExceptionsIllegalStateException- 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. Compatibility VersionJava 1.5 and above Example 1Output: Enter the Number you want: 880 Output value: 388080 Example 2Output: Enter Value of a: 12345 Enter Value of x: 123456 Enter Value of b: 1234567 Enter Value of y: 1234 Output: 1223461 Example 3Output: Not Found: JavaTpoint.com Found: 13 Not Found: + Found: 13 Not Found: = Not Found: 26.0 Not Found: true Found: 123456789098765432 Example 4Output: 21845 2869 -9557 -1877 1309 Example 5Output: 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) Next TopicJava-scanner-next-method |