Console input Statements
To use the Scanner class, the import Java.util.Scanner should be imported first;
The object is then established Scanner sc = new Scanner (system.in);
You can then receive a variety of data types from the console input.
Like what:
String s = sc.next ();//Receive console input for various data types
String s = sc.nextline ();//Receive console input for various data types
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 a space, until the carriage return.
Double d = sc.nextdouble ();
If you want to enter a character, you can take advantage of the Charat (index) method of the string.
For example, char ch = sc.next (). charAt (0);
You can also write directly: char ch = new Scanner (system.in). Next (). charAt (0);
Integral type: int a=new Scanner (system.in). Nextint ();
Floating point: Float b=new Scanner (system.in). Nextfloat ();
Floating point: Double b=new Scanner (system.in). nextdouble ();
String: String S=new Scanner (system.in). Next ();
String s=new Scanner (system.in). nextline ();
Ways to get characters:
char ch = new Scanner (system.in). Next (). charAt (0);
Eclipse Console input