The three methods are as follows:method One: Receive a character from the console and print it outimport java.io.*;Public static void Main (String [] args) throws ioexception{System.out.print ("Enter a Char:");Char i = (char) System.in.read ();System.out.println ("Your char is:" +i);} Although this method implements the input character from the keyboard, System.out.read () can only be obtained for one character, and the type of the variable entered is only char, and when we enter a number, we want to get an integer variable, We also have to modify the variable types, which makes it more cumbersome. method Two: Receive a string from the console and print it out. In this topic, we need to use the BufferedReader class and the InputStreamReader classimport java.io.*;Public static void Main (String [] args) throws ioexception{InputStreamReader ISR = new InputStreamReader (system.in);bufferedreader br = new BufferedReader (ISR);String str = "";System.out.println ("Enter Your Value:");str = br.readline ();System.out.println ("Your value is:" +str);}so we can get the string we entered. method Three: This method I think is the simplest, the most powerful, is to use the scanner classimport Java.util.Scanner;Public static void Main (String [] args) {Scanner sc = new Scanner (system.in);System.out.println ("Please enter your name:");String name = Sc.nextline ();System.out.println ("Please enter your Age:");int age = Sc.nextint ();System.out.println ("Please enter your salary:");Float salary = sc.nextfloat ();System.out.println ("Your information is as follows:");System.out.println ("Name:" +name+ "\ n" + "Age:" +age+ "\ n" + "Salary:" +salary);}This code has shown that the scanner class, whether it's a string or integer data or a variable of type float, can implement functionality with a small change. Finally, a small summary of the difference between next () and nextline ():
In Java, the next () method is not to receive the space, before the receipt of valid data, all the space or TAB key input is ignored, if there is valid data, you encounter these keys exit. nextline () can receive a space or TAB key, and its input should end with the ENTER key.
Java Read keyboard input