System.out
?System.out.println("Some string" + 123)
sends characters to the ouput stream."Some string" + 123
converts the integer
123
from a primitive numeric type into characters
that are appended to "Some string".
The following program reads characters from the keyboard into
the String called inData
.
Then the characters stored in that String are sent to the monitor.
The details of this program are explained in the next several pages.
import java.io.*; class Echo { public static void main (String[] args) throws IOException { InputStreamReader inStream = new InputStreamReader( System.in ) ; BufferedReader stdin = new BufferedReader( inStream ); String inData; System.out.println("Enter the data:"); inData = stdin.readLine(); System.out.println("You entered:" + inData ); } }
The line import java.io.*;
says that the package java.io
will be used.
The * means that any class inside the package might be used.
Here is how this program runs:
C:\users\default>java Echo Enter the data: This is what the user enters You entered:This is what the user enters C:\users\default>