Java Scanner nextShort() Method
The nextShort() is a Java Scanner class method which is used to scan the next token of the input as a Short. There is two different types of Java nextShort() 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 Short in the default radix.
nextShort(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 Short in the specified radix.
Following is the declaration of nextShort() method:
The nextShort() method returns the Short 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: 40 Output value: 840
Not Found :Facebook.com Found :7 Not Found :+ Found :7 Not Found := Not Found :26.0 Not Found :true
Not Found: JavaTpoint.com Found: 13 Not Found: + Found: 13 Not Found: = Not Found: 26.0 Not Found: true Found: 12345
Exception in thread "main" java.lang.IllegalArgumentException: radix:555 at java.base/java.util.Scanner.setRadix(Scanner.java:1368) at java.base/java.util.Scanner.nextShort(Scanner.java:2114) at myPackage.ScannerNextShortExample4.main(ScannerNextShortExample4.java:9)