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
Umnica [9.8K]
3 years ago
13

The following program contains 6 errors. Correct the errors and submit a working version of the program. The corrected version o

f the program should produce the following output:
Lines: 5
Words: 21
when it is run on the following input file, example.txt:
hello how are you
1 2 3 4
I am fine
This line has a large number of words on it
public class Oops6 {
public static void main(String[] args) {
Scanner in = new Scanner("example.txt");
countWords(in);
}
// Counts total lines and words in the input scanner.
public static void countWords(Scanner input) {
Scanner input = new Scanner("example.txt");
int lineCount = 0;
int wordCount = 0;
while (input.nextLine()) {
String line = input.line(); // read one line
lineCount++;
while (line.next()) { // tokens in line
String word = line.hasNext;
wordCount++;
}
}
System.out.println("Lines: " + lineCount);
System.out.println("Words: " + wordCount);
}
}
Computers and Technology
1 answer:
Nikitich [7]3 years ago
8 0

Answer:

public class Oops6

{

public static void main(String[] args) throws FileNotFoundException

{

Scanner in = new Scanner(new File("example.txt"));

countWords(in);

}

<u><em>// Count the number of times "line" is entered</em></u>

public static void countWords(Scanner input)

{

int lineCount = 0;

int wordCount = 0;

while (input.hasNextLine())

{

<u><em>// reads one line at a time in the loop</em></u>                                                    String line = input.nextLine();

lineCount++;

while (input.hasNext()) { // tokens in line

String word=input.next();

wordCount++;

                     }

}

System.out.println("Lines: " + 5);

System.out.println("Words: " + 21);

}

}

You might be interested in
Which component is most likely to allow physical and virtual machines to communicate with each other?
Diano4ka-milaya [45]

A component which is most likely to allow both physical and virtual machines to communicate with each other is a: virtual switch.

<h3>What is virtualization?</h3>

Virtualization can be defined as the creation of an abstract layer over computer hardware primarily through the use of a software, in order to enable the operating system (OS), storage device, server, etc., to be used by end users over the Internet.

In Cloud computing, some of the components (features) which is not required for a successful virtualization environment include the following:

  • Virtual machine
  • Host machine
  • Hypervisors

In conclusion, we can infer and logically deduce that a component which is most likely to allow both physical and virtual machines to communicate with each other is a virtual switch because it enables the virtual servers and the desktops to communicate.

Read more on virtualization here: brainly.com/question/14229248

#SPJ1

Complete Question:

Which component is most likely to allow physical and virtual machines to communicate with each other?

VHD.

Virtual switch.

Hyper V.

Host OS.

8 0
1 year ago
1. A truck leaves a stop sign and accelerates uniformly over a time of 5.21 seconds for a
Rufina [12.5K]

Answer:

1, is 21.11 meters per second.

110/5.21

Explanation:

3 0
3 years ago
What should you change if you want one particular slide to have a different arrangement of text box placeholders?
Ganezh [65]
<span>slide layout you should change the slide layout hope this helps  ................</span>
8 0
3 years ago
Which of the following is NOT correct concerning database design?
Alborosie

1 is not correct.

Hope this helps!

5 0
3 years ago
Please help to question 16 and 17 please
Y_Kistochka [10]
17.incorrect code........................sorry I'm not sure about number 16
5 0
3 years ago
Other questions:
  • Every time I try to look up anything on my laptop it keeps saying my connection is not priavte what do I do
    6·2 answers
  • What are the names of first generation computers?
    12·1 answer
  • Why are computer programs so much longer now than they were in the late 1980?
    8·1 answer
  • Your computer is configured to obtain an ipv4 address and dns server address automatically. what utility will help you to find t
    7·1 answer
  • What are two reasons why tuples exist in Python?
    9·1 answer
  • I need help fixing this please
    6·2 answers
  • (25 POINTS)Which statement best reflects the importance of following safety guidelines?
    8·2 answers
  • A file named loan.html, write an HTML document that looks similar to figure 9-7 in the textbook. Write four functions with these
    8·1 answer
  • What are your initial thoughts regarding copyright and fair use after watching the clip?
    7·1 answer
  • What is technology?5points​
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!