189k views
4 votes
Consider the following code snippet.a.File inputFile = new File("dataIn.txt");b.Scanner in = new Scanner(inputFile);c.while (in.hasNext()){String input = in.next();}Which of the following statements about this code is correct?

User Simpom
by
5.4k points

1 Answer

5 votes

Answer:

a) This code will read in a word at a time from the input file.

Step-by-step explanation:

Below are the statements we are expected to choose the correct one from:

a) This code will read in a word at a time from the input file.

b) This code will read in the entire input file in one operation.

c) This code will read in a line at a time from the input file.

d) This code will read in a character at a time from the input file.

Further Explanation:

The statements have been coded in Java. File inputFile = new File("dataIn.txt"); is used to construct a file object with the name of the input file. The the file object is used to construct a Scanner object. Scanner in = new Scanner(inputFile);

Scanner provides methods like hasNextLine() to read data from the input file, this is what was used in the while loop process, to read the word at a time from the input file. So that the code will read in a word at a time from the input file.

User Forrert
by
5.0k points