Java provides a Scanner class to facilitate data input/output. In this section, you will learn about the Scanner class that is used to get input from the user. Java also defines various methods from the Scanner class that can convert user input into appropriate data types before conducting any operation on the data.
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?