Java -- Method for retrieving data input from the console, java Console
1. Use the standard input string System. in
System. in. read (); // read-only data in one byte at a time, but we often want to obtain a string or a group of numbers.
2. Use numeric to obtain a string or a group of numbers
// The next () method of substring is used to obtain the user input string; nextInt () converts the obtained input string to the integer type; similarly, nextFloat () is converted to the floating point type; nextBoolean () convert to boolean.
// Enter space, tab, and enter as the Terminator;
System. out. print ("input n :");
Repeated scan = new partition (System. in );
String read = scan. nextLine ();
Int n = Integer. parseInt (read );
System. out. println ("input data n =" + n );
3. Use BufferedReader to obtain the input with spaces
// To obtain the input containing spaces, use the java. io. BufferedReader class;
BufferedReader br = new BufferedReader (new InputStreamReader (System. in ));
String read1 = null;
System. out. print ("input data :");
Try {
Read1 = br. readLine ();
} Catch (IOException e ){
E. printStackTrace ();
}
System. out. println ("input data:" + read1 );
String [] split_num = read1.split ("");
Int [] split_num2int = new int [n];
For (int I = 0; I <split_num.length; I ++ ){
System. out. print (split_num [I] + "");
Split_num2int [I] = Integer. parseInt (split_num [I]);
}