Scanner nextLong Method in Java
Well, sometimes, we are required to take some long-type data as user input. If we are in such a situation, we can make use of this method. We can simply say that the nextLong method is going to help us get the long-type data as user input.
Getting the long type data as user input (nextLong method)
Let’s have a look at a program, where we try to demonstrate the nextLong method.
package com.company;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
long storeslong = scanner.nextLong();
System.out.println(storeslong);
}
}
So, if you try implementing the above program, you can give input of type long. The range of long is from -263 to 263 – 1. we are storing the long data into the long type variable.