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
2.13 LAB: Branches: Leap Year
Neporo4naja [7]

Answer:

The program in Python is as follows:

year = int(input("Enter a year: "))

print(year,end=" ")

if year % 4 == 0:

  if year % 100 == 0:

      if year % 400 == 0:           print("is a leap year")

      else:           print("is not a leap year")

  else:       print("is a leap year")

else:   print("is not a leap year")

Explanation:

This gets input for year

year = int(input("Enter a year: "))

This prints year, followed by a blank

print(year,end=" ")

If year is divisible by 4

if year % 4 == 0:

If yes, check if year is divisible by 100

  if year % 100 == 0:

If yes, check if year is divisible by 400; print leap year if true

      if year % 400 == 0:           print("is a leap year")

print not leap year if year is not divisible by 400

      else:           print("is not a leap year")

print leap year if year is not divisible by 100

  else:       print("is a leap year")

print leap year if year is not divisible by 4

else:   print("is not a leap year")

5 0
3 years ago
You are an administrator for contoso.com. you have two servers called server1 and server2 that run windows server 2012 and have
gogolik [260]
You should configure a joint sever

6 0
2 years ago
Which education and qualifications are most helpful for Law Enforcement Services careers? Check all that apply.
bixtya [17]

Explanation:

For IAS..we need a high amptual amount of knowledge..

For IPS..we need master degree and physical fitness too..

For An Advocate..we need Master degree and social Skills..

so..the education and qualifications depends on the various jobs..

HOPE THE ANSWER IS USEFUL

3 0
2 years ago
What's the inputs and outputs in a kitchen?
SashulF [63]
I really don't know...
6 0
3 years ago
Write a Java test program, named TestGuitar, to create 3different Guitars representing each representing a unique test case and
alina1380 [7]

Answer:

Explanation:

//Guitar.java

import java.awt.Color;

import java.lang.reflect.Field;

import java.util.Random;

public class Guitar

     /**

     * these two fields are used to generate random note and duration

     */

     static char[] validNotes = 'A', 'B', 'C', 'D', 'E', 'F', 'G' ;

     static double[] validDuration = 0.25, 0.5, 1, 2, 4 ;

     /**

     * basic guitar attributes

     */

     private int numStrings;

     private double guitarLength;

     private String guitarManufacturer;

     private Color guitarColor;

     public Guitar()

           /**

           * default constructor

           */

           numStrings = 6;

           guitarLength = 28.2;

           guitarManufacturer = Gibson;

           guitarColor = Color.RED;

     

     public Guitar(int numStrings, double guitarLength,

                 String guitarManufacturer, Color guitarColor)

           /**

           * parameterized constructor

           */

           this.numStrings = numStrings;

           this.guitarLength = guitarLength;

           this.guitarManufacturer = guitarManufacturer;

           this.guitarColor = guitarColor;

     

     /**

     * required getters and setters

     */

     public static char[] getValidNotes()

           return validNotes;

     public static void setValidNotes(char[] validNotes)

           Guitar.validNotes = validNotes;      

     public static double[] getValidDuration()

           return validDuration;

     public

4 0
3 years ago
Other questions:
  • In these weeks readings, we learned about the CIA Triad and how each exhibits dependence on the other. Give examples of how fail
    12·1 answer
  • For security reasons a network administrator needs to ensure that local computers cannot ping each other. which settings can acc
    5·1 answer
  • Which element would the search element be compared to first, if abinary search were used on the list above?
    6·1 answer
  • What does Putting a word in quotation marks on your search bar do on google?
    12·1 answer
  • PLZ help
    5·1 answer
  • .<br>1.<br>CPU<br>f. ALU<br>. CU<br>h. CRT<br>g. LED<br>​
    15·1 answer
  • A location in memory which stores a value, the value can change as the program is running is
    12·1 answer
  • Help me please. I'LL MARK BRAINIEST
    15·1 answer
  • Do you think Mortal Combat is cool?
    10·2 answers
  • to allow excel to change the cell references in a formula or function from row to row or column to column as you fill with it, y
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!