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
Write a Java program that reads an 8-bit binary number from the keyboard as a string and then converts it into decimal. For exam
cestrela7 [59]

Answer:

public class Brainly

{

 public static void main(String[] args)

 {

   BinaryConverter conv = new BinaryConverter();

   String binStr = "01001101";

   System.out.print(binStr + " in decimal is "+conv.BinToDec(binStr));

 }

}

public class BinaryConverter

{

 public int BinToDec(String binStr)

 {

   int d = 0;

   while(binStr.length() > 0)

   {

     d = (d << 1) + ((binStr.charAt(0) == '1') ? 1: 0);

     binStr = binStr.substring(1);

   }

   return d;

 }

}

Explanation:

The program "eats" the string from left to right, and builds up the integer representation in variable "d" on the go. While there are digits left, it shifts the previous result to the left and sets the least signficant bit to 1 only if the corresponding string character is a 1.

5 0
3 years ago
What wired channel, commonly used for cable tv, consists of an insulated copper wire wrapped in a solid or braided shield placed
Airida [17]
the answer is A coaxial cable
8 0
3 years ago
For this step, submit your work in the programming environment by running your code, checking your code for a score. The score y
34kurt

A sample HTML code that contains headers, paragraph tags, hyperlinks is

  • <h1> This is a header </h1>
  • <h2> This is a subtitle heading </h2>
  • <p> This is a paragraph </p>
  • <a href=”www.brainly.com”> Brainly Website </a>

<h3>What is HTML?</h3>

This is the building block of a website and is an acronym that means Hypertext Markup Language.

The HTML code that can be used to add a sample image is: "<img src="pic_Brainly.jpeg" alt="Brainly" width="500" height="333">

The src code means the specific location of the external resource

The width and height show how tall and wide the image would be.

The alt shows the alternative information for the image that can be seen when a person hovers over the image on the website.

Read more about HTML and CSS here:

brainly.com/question/24051672

#SPJ1

3 0
2 years ago
The cyclical, multistep process by which designers and engineers design, build, and taste a new product is called:
zzz [600]
The answer is Design Process.  <span>The cyclical, multistep process by which designers and engineers design, build, and taste a new product is called Design Process.   </span><span>There are multiple steps, including exploring, designing, planning, making, testing, and revising.</span>
7 0
3 years ago
Which hardware device connects your network to the internet?
pentagon [3]
The Ethernet Cord 

Hope this helps,

kwrob :)

6 0
3 years ago
Other questions:
  • Do transformers have life insurance or car insurance? If you chose life insurance, are they even alive?
    7·1 answer
  • What provides access to the internet?
    6·1 answer
  • What is MARC? Discuss structure of MARC
    8·1 answer
  • One way to describe the note-taking tool eNotes is to call it an<br> Someone help ._.
    9·2 answers
  • A(n) _______________ loop usually occurs when the programmer forgets to write code inside the loop that makes the test condition
    13·1 answer
  • Of the various trends affecting the advertising and promotion industry, _____________ offers an opportunity for advertisers to d
    9·1 answer
  • PLEASE HELP ASAP!! Timed test!!
    12·1 answer
  • Is it possible build a real time machine?
    7·2 answers
  • Queries are questions true or false?
    9·1 answer
  • In which number system do the digital computer work​
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!