Completion requirements
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.
9. Details
Answer:
Yes. (Although frequently those characters are converted to a numeric type after they have been read in.)
Details
Details
import java.util.Scanner; public class Echo { public static void main (String[] args) { String inData; Scanner scan = new Scanner( System.in ); System.out.println("Enter the data:"); inData = scan.nextLine(); System.out.println("You entered:" + inData ); } } |
Later on we will do something special to convert strings of digits into primitive numeric types. This program does not do that.
public class Echo
The program defines a class namedEcho
that contains a single method, itsmain()
method.
public static void main ( String[] args )
Allmain()
methods start this way. Every program should have amain()
method.
String inData;
The program creates a reference variableinData
which will soon refer to aString
object.
Scanner scan = new Scanner( System.in );
This creates aScanner
object, referred to by the reference variablescan
.
Question 9:
What data stream is this
Scanner
connected to?