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
freeeeeeeeeeeeeeeeee poiiiiiiiiiiiiiiiiiiiiiiiiiinnnnnnnnnnnnnnnnnnnnnnttttttttttttttttttttttttsssssssssssssssssss
Jlenok [28]

Answer:

i want some

Explanation:

EEEEEEEEEEE

7 0
3 years ago
Read 2 more answers
Examine the efficiency the various recovery algorithms used in deadlock handling
sineoko [7]

Solution:

The process of transaction can guarantee the reliability of business applications. Locking resources is widely used in distributed transaction management (e.g; two phase commit, 2PC) to keep the system consistent. The locking mechanism, however, potentially results in various deadlocks. In service oriented architecture, the deadlock problem becomes even worse because multiple transactions try to lock shared resources in the unexpectable way due to the more randomicity of transaction requests, which has not been solved by existing research results. In this paper, we investigate how to prevent local deadlocks, caused by the resource competition among multiple sub-transactions of a gl obal transaction, and global deadlocks from the competition among different global transactions. We propose a replication based approach to avoid the local deadlocks, and a timestamp based approach to significantly mitigate the global deadlocks. A general algorithm is designed for both local and global deadlock prevention. The experimental results demonstrate the effectiveness and efficiency of our deadlock prevention approach. Further, it is also proved that our approach provides higher system performance than traditional resource allocation schemes.

This is the required answer.

4 0
3 years ago
What are minimum computer requirements for a software program?
Bumek [7]
<span><span>Operating system: Windows 2000/XP
</span><span>CPU: Pentium 4 1.5 GHz or Athlon XP 1500+ processor or higher
</span><span>Memory: 384 MB RAM</span></span>
8 0
4 years ago
Most operating systems perform these tasks. coordinating the interaction between hardware and software allocating RAM to open pr
goldenfox [79]

Answer:

The answer are A.) Coordinating the interaction between hardware and software And B.) Allocating RAM to open programs

Explanation:

Hope this helps :)

5 0
3 years ago
Who is the smartest avenger??? :)
Rom4ik [11]

Answer:

Iron Man

Explanation:

5 0
3 years ago
Read 2 more answers
Other questions:
  • A hard drive that uses fde is often referred to as a(n) ____.
    11·1 answer
  • What does computer means?
    9·2 answers
  • On a piano, a key has a frequency, say f0. Each higher key (black or white) has a frequency of f0 * rn, where n is the distance
    10·1 answer
  • Is USA TestPrep a test-taking site that won't let you access other windows without kicking you off?
    13·1 answer
  • A program contains the following function definition: def cube(num): return num * num * num Write a statement that passes the va
    13·1 answer
  • What is output if the user types in 8
    15·1 answer
  • Select all the correct answers. Which two statements are true about electric current through a circuit? Current flows from a pos
    14·1 answer
  • It is a read mostly memory that can be electronically written into any time without arising prior contact
    12·1 answer
  • 5.5 Learning Objective: To demonstrate that the student understands the definition of Big O. To demonstrate that the student und
    11·1 answer
  • Whats th diffence between a fwireless speaker and a wird speakr
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!