Scannertest.java using the scanner class for input
Import Java.util.Scanner;
Class scannertest{
public static void Main (string[] args) {
Scanner Scanner =new Scanner (system.in);
System.out.println ("Please enter a number:");
int A=scanner.nextint ();
System.out.printf ("%d squared is%d\n", a,a*a);
}
}
Scanner class, it is important to note that the program is preceded by an import statement to pour into this class. The program uses system.in as a parameter to construct a scanner object.
If you use traditional system.in for input, you generally need more steps. Because System.in's read () method can only read a character, not easy to use, to "wrap" system.in, use it to construct a InputStreamReader object, and then construct a BufferedReader object, The BufferedReader object has a ReadLine method that can be used to read a string of characters. If you need to convert the input string into a number, such as an integer int or a real double. Integer.parseint and Double.parsedouble methods are available at this time.
My java--a comprehensive program of knowledge points