Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStreamReader;
Import Java.util.Scanner; public class Entertest {public static void main (string[] args) {//Main method Chartest (); Call the System.in method Readtest (); Call the Readtest method Scannertest ()//Call Scannertest method}/** * System.in and System.out method * Disadvantage One: This method can get the characters entered from the keyboard, but only Gain * Disadvantage two for one character: gets only the char type.
If you want to get int,float and other types of input, more trouble.
*/public static void Chartest () {try{System.out.print ("Enter a Char:");
char i = (char) System.in.read ();
System.out.println ("Yout Enter Char is:" + i);
catch (IOException e) {e.printstacktrace ();
}/** * InputStreamReader and BufferedReader method * Advantages: Can get the keyboard input string * Disadvantage: How to get the int,float and other types of still need to convert
*/public static void Readtest () {System.out.println ("readtest, please Enter Data:"); InputStreamReader is = new InputStreamReader (system.in); New Construction InputstreamreAder object BufferedReader br = new BufferedReader (IS);
Get the constructed method into the BufferedReader try{//There is a Ioexcepiton in the method that needs to capture String name = Br.readline ();
System.out.println ("Readtest Output:" + name);
catch (IOException e) {e.printstacktrace (); The method in/** * Scanner class * Advantage One: can get keyboard input string * Advantage Two: Have ready-made access to the type of data such as Int,float, very powerful, but also very convenient; * * Publi
c static void Scannertest () {Scanner sc = new Scanner (system.in);
System.out.println ("Scannertest, please Enter Name:"); String name = Sc.nextline ();
Reads the string input System.out.println ("Scannertest, please enter Age:"); int age = Sc.nextint ();
Read int input System.out.println ("Scannertest, please enter Salary:"); float salary = sc.nextfloat ();
Reads the float type input System.out.println ("Your information is as below:");
System.out.println ("Name:" + name + "\ n" + "Age:" +age + "\ n" + "Salary:" +salary); }
}
Summary:
to get input from the keyboard:
Python provides, Python2 has Raw_input (), Python3 has input ().
C provides the scanf () function
C + + provides the CIN () function to get keyboard input
There is no ready-made function in Java to get keyboard input, but it can still be implemented using the above method, where method three should be the simplest and most convenient.