InputStreamReader inStream = new InputStreamReader( System.in ) ; BufferedReader stdin = new BufferedReader( inStream );
What is the variable inStream used for?
The variable is used to connect the InputStreamReader
to the
BufferedReader
.
Once the connection is made, the variable is not used again. In fact, you don't need to use it at all because the connection can be made all in one line:
BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
If you want, you can think of this one very long command that means "get ready to read stuff in." The complete program is now:
import java.io.*; class Echo { public static void main (String[] args) throws IOException { BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); String inData; System.out.println("Enter the data:"); inData = stdin.readLine(); System.out.println("You entered:" + inData ); } }
This one statement takes up two lines. This is OK. Statements end with a semicolon, not at the end of a line. Use indenting to show when a long statement has been written on two (or more) lines.