The NextShort method in java
Using the NextShort method, we can get the short type data as user input. So, in some situations, where we are required to take the short type data as user input, we can make use of the NextShort method. Let’s have a look at a simple program, in which, we are going to try to get the short type data as user input.
Getting short type data as user input (NextShort method)
Have a look at the below program →
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
short storesshort = scanner.nextShort();
System.out.println(storesshort);
}
}
So, if you try to implement the above program, you will see that you are able to get the short type user input from the user, which ranges from -32768 to 32767. If the input goes out of this range, then it throws an error since we are trying to get something as an input that is out of range.