1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ainat [17]
3 years ago
9

Assume inputFile is a Scanner object used to read data from a text file that contains a number of lines. Each line contains an a

rbitrary number of words, with at least one word per line. Select an expression to complete the following code segment, which prints the last word in each line. while (inputFile.hasNextLine()) { String word = ""; String line = inputFile.nextLine(); Scanner words = new Scanner(line); while (_________________) { word = words.next(); } System.out.println(word); }
Computers and Technology
1 answer:
anzhelika [568]3 years ago
7 0

Answer:

words.hasNext()

Explanation:

Given the code snippet below:

  1.        while (inputFile.hasNextLine()) {
  2.            String word = "";
  3.            String line = inputFile.nextLine();
  4.            Scanner words = new Scanner(line);
  5.            while (words.hasNext()) {
  6.                word = words.next();
  7.            }
  8.            System.out.println(word); }
  9.    }

We have a inputFile Scanner object that can read data from a text file and we presume the inputFile has read several rows of data from the text file. So long as there is another line of input data available, the outer while loop will keep running. In each outer loop, one line of data will be read and assign to line variable (Line 3). Next, there is another Scanner object, words, which will take the current line of data as input. To get the last word of that line, we can use hasNext() method. This method will always return true if there is another tokens in its input. So the inner while loop will keep running so long as there is a token in current line of data and assign the current token to word variable. The word will hold the last token of current line of data upon exit from the inner loop. Then we can print the output (Line 8) which is the last word of the current line of data.

You might be interested in
What is the age group for the silent genration
Maurinko [17]
21 years old. If you take 1944-1923 you get 21 because that would be ho wold they are
7 0
3 years ago
The database cannot be migrated to a different engine because sql server features are used in the application’s net code. The co
Nezavi [6.7K]

Answer:

Explanation:

B is correct

3 0
2 years ago
I dont know how to put the negative sigh on my computer
valina [46]
You put the dash on the right side up top ape
8 0
2 years ago
Read 2 more answers
When you sort a cell range using a to z or z to a, what is rearranged?
kvv77 [185]
Only those cells names. Most common mistake in excel. If you want to sort rows make sure you highlight everything and then use sort function on column
5 0
3 years ago
A stigma is
mario62 [17]
The answer to your question is A. A mark of social disgrace that sets tyre deviant apart from the rest of society. Hope I helped.
8 0
3 years ago
Read 2 more answers
Other questions:
  • ___ refers to all aspects of managing and processing information using computers and computer networks
    13·1 answer
  • What item on a business card is generally the most prominent?
    13·2 answers
  • In an is framework, ________ is the bridge between the computer side on the left and the human side on the right
    12·1 answer
  • James, a technician, needs to format a new drive on a workstation. He will need to configure read attributes to specific local f
    5·1 answer
  • What is the computer that is similar to a destop but smaller in size
    8·1 answer
  • What are 2 main differences betweenarrays andstructs?
    7·1 answer
  • What function returns a line and moves the file pointer to the next line?
    9·1 answer
  • Question is on the picture thank you
    10·1 answer
  • Pls help quick... will mark brainliest...
    15·1 answer
  • The computer stores currently used programs and data in ________.
    9·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!