First, using the Scanner class for console input
The scanner class in the document is defined as a simple text scanner which can parse primitive types and strings using regular expressions (one can use regular expressions to parse the base Simple text scanners of this type and string).
To use the Scanner class, first import the Import.util.Scanner;
Then set the object Scanner scan = new Scanner (system.in);
You can then receive a variety of data types from the console input.
Like what:
int x = Scan.nextint ();
String s = scan.next ();
String s = scan.nextline ();
(The difference between next and Nextline is that the former receives a string up to the first space, and the latter receives a string that can contain spaces, until the carriage return)
Double d = scan.nextdouble ();
If you want to enter a character, you can take advantage of the Charat (index) method of the string.
For example, char ch = scan.next (). charAt (0);
Java Learning diary-2 bits