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]
4 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]4 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
Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binar
MAXImum [283]

Answer:

thats what i was about to ask. im not sure

Explanation:

sorry   '-'

3 0
3 years ago
is a measurement that quantifies how much information can be transmitted over the network. A. Memory B. DMZ C. Bandwidth D. Clou
AnnZ [28]

Answer: Bandwidth....

6 0
3 years ago
4.
marshall27 [118]

Answer: c

Explanation:

5 0
3 years ago
________ management is a process of controlling changes in system requirements during software development.
Brums [2.3K]
<span>Change Control (CC) management is a process of controlling changes in system requirements during software development. </span>
8 0
3 years ago
1. What is a word processor program?
serg [7]
A word processor program is a software that can be used to create, edit and print documents.
5 0
1 year ago
Other questions:
  • Find an element inside a div using javascript
    12·1 answer
  • True or false over the course of ecological succession,species diversity increases over time?
    12·2 answers
  • In a relational database, the three basic operations used to develop useful sets of data are:
    10·1 answer
  • Ip addresses and their corresponding domain names are used to identify computers available through the internet.
    15·1 answer
  • Write about the future of Reliability and Security in Software Engineering.
    13·1 answer
  • You must obey any special signs or instructions as you pass a construction zone.
    14·2 answers
  • I really need help with this question
    14·1 answer
  • What is the command to list files in Unix and Unix like operating system?​
    15·1 answer
  • Which situation is the best choice for using telehealth?
    12·1 answer
  • when you enter a url, you’re creating a(n) ____ link, which is the full and complete address for the target document on the web.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!