1. Receive a character from the console and print it out.
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 obtains the input characters from the keyboard, system. Out. Read () can only be obtained for one character. At the same time, the type of the obtained variables can only be
CHAR: when we enter a number and want to get an integer variable, We have to modify the variable type, which is troublesome.
2. Receive a string from the console and print it out. In this question, we need to use the bufferedreader class and inputstreamreader class.
Public static void main (string [] ARGs) throws ioexception {
Bufferedreader BR = new bufferedreader (New inputstreamreader (system. In ));
String STR = NULL;
System. Out. println ("Enter your value :");
STR = Br. Readline ();
System. Out. println ("your value is:" + Str );
}
In this way, we can obtain the input string.
3. I think this method is the simplest and most powerful, that is, the use of the struct class.
Public static void main (string [] ARGs ){
Pipeline SC = new pipeline (system. In );
System. Out. println ("enter your name :");
String name = SC. nextline ();
System. Out. println ("Enter your age :");
Int age = SC. nextint ();
System. Out. println ("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 sectionCodeIt has been indicated that the category class can implement functions whether it is a string, an integer, or a float type variable, you only need to make a small change! No doubt he is the most powerful!