Want to learn BASIC time, get user input how simple, on an input; later, C, also quite simple, a scanf (); later, C + +, as simple as a cin <<; to Java here, trouble.
1, simple access to user input
The following is a basic example that contains an explanation:
1.import Java.io.BufferedReader;
2.import Java.io.InputStreamReader;
3.import java.io.IOException;
4.
5.public class Basicinput {
6.
7. Public static void Main (string[] args) {
8. try {
9. In Java, user input is obtained by InputStream (input stream)
.
Ten. System.in is the input stream of the system. By default, this input stream is connected
to the console (the command line). One by one
. InputStreamReader is the class used to read InputStream. A
. InputStreamReader is_reader = new InputStreamReader
(system.in);
-April. BufferedReader is typically used to read character
string content in InputStream.
. BufferedReader can read one row at a time.
. String str = new BufferedReader (is_reader). ReadLine ();
. Prints the read string to the screen.
. SYSTEM.OUT.PRINTLN ("You entered is:" + str); catch (IOException e) {
. E.printstacktrace ();
. }
24.}