Scanner class - user input
The Scanner
class retrieves data from the user and saves it to a variable.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in); // an object of the Scanner class with System.in assigned to it
String x = input.next(); // retrieving a string from the user
System.out.println(x);
int y = input.nextInt(); // retrieving an integer from the user
System.out.println(y);
double z = input.nextDouble(); // retrieving a decimal from the user
System.out.println(z);
}
}