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
ivanzaharov [21]
3 years ago
10

(Count the occurrences of words in a text file) Rewrite Listing 21.9 to read the text from a text file. The text file is passed

as a command-line argument. Words are delimited by whitespace characters, punctuation marks (, ; . : ?), quotation marks (' "), and parentheses. Count the words in a case-sensitive fashion (e.g., consider Good and good to be the same word). The words must start with a letter. Display the output of words in alphabetical order, with each word preceded by the number of times it occurs.
I ran my version of the program solution on its own Java source file to produce the following sample output:
C:\Users\......\Desktop>java CountOccurrenceOfWords CountOccurrenceOfWords.java
Display words and their count in ascending order of the words
1 a
1 alphabetical
1 an
2 and
3 args
2 as
1 ascending
1 catch
1 class
4 count
2 countoccurrenceofwords
1 create
1 display
1 else
3 entry
3 entryset
2 ex
1 exception
1 exit
1 file
2 filename
3 for
1 fullfilename
3 get
1 getkey
1 getvalue
1 hasnext
1 hold
5 i
3 if
2 import
2 in
3 input
2 int
1 io
3 java
6 key
3 length
2 line
1 main
3 map
1 matches
3 new
1 nextline
1 null
1 of
2 order
3 out
3 println
1 printstacktrace
2 public
2 put
2 scanner
1 set
1 split
1 static
5 string
4 system
2 the
1 their
1 to
1 tolowercase
2 tree
6 treemap
2 trim
1 try
1 util
1 value
1 void
1 while
9 words
C:\Users\......\Desktop>
Computers and Technology
1 answer:
Oksanka [162]3 years ago
3 0

Answer:

Explanation:

The following is written in Java. It uses File input, to get the file and read every line in the file. It adds all the lines into a variable called fullString. Then it uses regex to split the string into separate words. Finally, it maps the words into an array that counts all the words and how many times they appear. A test case has been created and the output can be seen in the attached image below. Due to technical difficulties I have added the code as a txt file below.

You might be interested in
In which of the following situations is having a good credit score important?
Triss [41]
<span>The correct answer is to be able to loan from banks. Having a good credit score, impacts one's approval for bank loans. It will enable a person to have a higher chance of getting his or her loan, approved by the banks, than those who have low credit scores. </span>
8 0
3 years ago
A website sells illegal and counterfeited materials. According to which law can the US Attorney General seek a court order to re
RideAnS [48]
The answer is SOPA or Stop Online Piracy Act. This bill was introduced by Lamar Smith a representative in US. Lamar passed this bill in the United states to enforce the law to combat online copyright, online trafficking, and other cyber crimes. There are many provisions on this bill including the court orders to request ISP (Internet Service Provided) to block access to that website.
3 0
3 years ago
Read 2 more answers
What is a mini computer and what are it’s typical applications?
Molodets [167]

Answer:

it is a computer of medium power more than a microcomputer but less than a.minuframe

3 0
2 years ago
Read 2 more answers
Write a statement that assigns treeHeight with the height of a tree given the distance from the tree (in feet) and angle of elev
Nina [5.8K]

Answer:

treeHeight = tangent of angleElevation * treeDistance

In java, we could write it as:

double treeHeight = (Math.tan(angleElevation) * treeDistance);

Math.tan(angleElevation) is an inbuilt java mathematical function used to calculate the tangent of a value and the return value is always double.

Explanation:

formula:

tangent of angleElevation = treeHeight/treeDistance

We want to assign treeHeight, so we cross-multiply and we get:

treeHeight = tangent of angleElevation * treeDistance

Off course, the treeHeight will be in feet also.

6 0
3 years ago
Which of the following is considered proper ergonomics?
dexar [7]

Answer:

The First One

Explanation:

because ergonomics is trying to make the person who is using the device be in a more natural position. Raising the keyboard will make the typer feel more comfortable.

5 0
2 years ago
Read 2 more answers
Other questions:
  • Points!!!!!!!! pls help
    13·2 answers
  • Which major and minor keys have no sharps or flats apex?
    5·2 answers
  • Positive thinkers tend to
    9·2 answers
  • Question 2 of 5
    8·1 answer
  • 30points for help
    14·1 answer
  • Which of the following sets of acronyms is concerned with encoding data for secure transmission?
    11·1 answer
  • Rick is linking different pages in his website. Match the value of the attribute to its meaning to enable Rick to choose the mos
    13·1 answer
  • Guys, what does Product Analysis mean? please say it in a simple way.
    10·1 answer
  • SHORT ANSWERS:
    7·1 answer
  • List out any four hardware and software components required for multimedia​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!