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
Tom and jerry opened a new lawn service
DedPeter [7]
That’s cool sirrrrrrrr
6 0
3 years ago
Read 2 more answers
Many people describes computers as complex machine. what can this mean?
Airida [17]
They work in many different ways?
8 0
4 years ago
You have been tasked with finding the routers that have been installed between two networks. what utility would you use to provi
Kazeer [188]
Netstat -r

Should take care of it.
4 0
3 years ago
If you must transmit a file over an insecure channel, one way to prevent its contents from being seen by someone who might inter
natali 33 [55]

Answer:

connect to the network from a remote location using a VPN.

Explanation:

VPN stands for virtual private network, it allows computers to establish a secure connection through an encrypted tunnel for exchanging data between two end points when communicating through insecure channels like the internet.

8 0
3 years ago
1. software that helps run the computer hardware
leva [86]
1. System software 2. Mother board 3. Program 4.CPU 5. Laptop




7 0
4 years ago
Other questions:
  • Vlad is the leader of a group; he receives most of the messages from the group members, and he provides most of the information
    6·1 answer
  • Call 334-399-4201 to annoyed my mom
    13·1 answer
  • Read the excerpt from The Code Book. Other attacks include the use of viruses and Trojan horses. Eve might design a virus that i
    13·1 answer
  • Write a program that prompt the user to enter the coordinate of two points (x1, y1) and (x2,y2), and displays the slope of the l
    10·1 answer
  • 1. What is JavaScript?
    15·1 answer
  • Describe Relational Query Languages and Operations.
    15·1 answer
  • Which of the following, when used in conjunction with hyperlinks, can be useful for easily navigating a Word document? : *
    7·1 answer
  • :(.
    5·2 answers
  • 4.3 mini programs AP computer science
    14·1 answer
  • if a hacker wants to exploit the TCP three-way handshake, what is the most effective way to go about it?
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!