Input and Output
6. Example I/O Program
Answer:
Yes,
System.out.println( "Some string" )
sends characters to the output stream.
Example I/O Program
Here is a picture of a Java program doing character input and output. In this picture, the white box represents the entire program. The program has imported Scanner
for use with input, and has imported System.out
for
use with output.
To use the methods of a Scanner
an object must be constructed. (The diagram shows the object as a rectangle.)
The nextLine()
method of Scanner
reads one line of character data from the keyboard. The characters go into a String
object. An assignment statement puts a reference
to the object in the reference variable inData
. To output the characters to the monitor, the program uses the println()
method of System.out
.
Question 6:
Do you suppose that a
Scanner
object has more methods than the one method in this picture?