Scanner is a class in the java.util package that allows the user to read inputs of various data types from different sources such as the console or a file.
The nextLong() method is a Scanner method used to read a long value from the user's input. It handles any leading whitespace characters and waits until the user inputs a long value.
Here is an example of using nextLong() to read a long value from the console:
import java.util.Scanner;
public class Example { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Please enter a long value: "); long myLong = scanner.nextLong(); System.out.println("You entered: " + myLong); } }
In this example, we first import the Scanner class from the java.util package. We then create a new Scanner object to read input from the console. We prompt the user to enter a long value and use the nextLong() method to capture the input. Finally, we print the captured value back to the console.
Overall, the nextLong() method is a useful tool for reading long values from the user and is part of the java.util package.
Java Scanner.nextLong - 30 examples found. These are the top rated real world Java examples of java.util.Scanner.nextLong extracted from open source projects. You can rate examples to help us improve the quality of examples.