CountOccurrenceOfWords.java) Rewrite Listing 21.9 to display the words in ascending order of occurrence counts. Listing 1 import
Question:
CountOccurrenceOfWords.java) Rewrite Listing 21.9 to display the words in ascending order of occurrence counts.
Listing
Transcribed Image Text:
1 import java.util.*; 2 3 public class CountOccurrence0fWords { 4 public static void main(String[] args) { // Set text in a string String text = "Good morning. Have a good class. " + "Have a good visit. Have fun!"; 5 // Create a TreeMap to hold words as key and count as value Map
1 import java.util.*; 2 3 public class CountOccurrence0fWords { 4 public static void main(String[] args) { // Set text in a string String text = "Good morning. Have a good class. " + "Have a good visit. Have fun!"; 5 // Create a TreeMap to hold words as key and count as value Map map = new TreeMap<>(); 10 11 12 13 String[] words = text.split("[ \n\t\r.,;:!?(){}]"); for (int i = 0; i < words.length; i++) { String key = words[i].toLowerCase(); 14 |15 if (key.length() > 0) { if (!map.containskey(key)) { map.put(key, 1); 16 |17 18 19 20 21 22 23 24 25 26 27 28 29 30 else { int value = map.get(key); value++; map.put(key, value); // Get all entries into a set Set> entrySet = map.entrySet(); // Get key and value from each entry for (Map.Entry entry: entrySet) System.out.println(entry.getKey() + "\t" + entry.getValue()); 31 32 33 34 35 } a 2 class fun good have 3 morning visit
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 60% (10 reviews)
Output Words in ascending order of occurrence counts Good ...View the full answer
Answered By
Shivani Dubey
Hello guys, I am very good with the Advance mathematics, Calculus, Number theory, Algebra, Linear algebra, statistics and almost all topics of mathematics. I used to give individual tutoring students in offline mode but now want to help students worldwide so I am joining here. I can also give solutions in various coding languages of mathematics and software like mathematica, R, Latex, Matlab, Statistica, etc.
feel free to ask any doubt regarding mathematics
5.00+
2+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Rewrite Listing 18.7, DirectorySize.java, without using recursion. Listing 1 import java.io.File; 2 import java.util.Scanner; 3 4 public class DirectorySize { public static void main(String[] args) {...
-
Rewrite Listing 21.7 CountKeywords. java to read in a Java source code file and count the occurrence of each keyword in the file, but don?t count the keyword if it is in a comment or in a string...
-
Rewrite Listing 2.10, ComputeChange. java, to fix the possible loss of accuracy when converting a float value to an int value. Read the input as a string such as "11.56". Your program should extract...
-
Find reactions of support 1,2 and 3 F=10KN, a=2m, ?a=60 (45%) F 2a
-
Given a fixed set of players N, each coalition T N determines a unanimity game uT (example 1.48) defined by 1. For each coalition S c N, recursively define the marginal value of a coalition by...
-
Pike Creek Golf Club currently has 375 members who pay annual dues to play golf on the course. Historical records show that 38% of the members use the course at least once a week during the summer...
-
Think of some functional teams that you either belong to or have belonged to, or have had some contact with. LO6
-
1. How well does Fog Creek Softwares pay structure meet (a) The legal requirement of equal pay for equal work; (b) The conditions of product markets; and (c) The conditions of labor markets? 2. Joel...
-
Prepare journals entries for the following assuming that Mygoodoh Inc. uses a perpetual inventory method and records purchases at their net amounts. Prepare journals entries for the following...
-
Some politicians have proposed changing the way Social Security benefits are taxed. One proposal would increase the amount of Social Security benefits included in gross income to 100 percent. A tax...
-
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...
-
Revise the program in Listing 21.7. If a keyword is in a comment or in a string, don?t count it. Pass the Java file name from the command line. Assume that the Java source code is correct and line...
-
Discuss similarities and differences between the Ohio State University Leadership Model and the Leadership Grid.
-
According to a recent study, 21% of American college students graduate with no student loan debt. Suppose we obtain a random sample of 106 American college students and record whether or not they...
-
Differentiate the following with respect to x: a. y=5x+2x + x + 15 b. y=4x+3x - 4x - 10 c. y = 3Sin(5x) d. y = 3Cos(3x) e. y=10e -25x f. y = log(6x)
-
Question 2. The rate of drug destruction by the kidneys is proportional to the amount of the drug in the body. The constant of proportionality is denoted by K. At time t the quantity of the drug in...
-
5. 6. -1 (4a) U u X2 1 X2 -2 x -1 -2 12 (4b) U -2 2 Y y 16 x2 X2 3 1 (4c) U u - x 2 Y y -8 Y y -20 5 x X2 2 Find the state space models of the three systems shown in Fig. 4a, Fig. 4b, and Fig. 4c,...
-
Given the following data for Mehring Company, compute total manufacturing costs, prepare a cost of goods manufactured statement, and compute cost of goods sold. Direct materials used $230,000...
-
Refer to Exercise 60. a. Construct and interpret a 99% confidence interval for the difference between the true means. If you already defined parameters and checked conditions in Exercise 60, you dont...
-
Two mutually exclusive investment alternatives are being considered. Alternative A requires an initial investment of $20,000 in a machine. Annual operating and maintenance costs are anticipated to be...
-
How can a composite signal be decomposed into its individual frequencies?
-
Given the following periods, calculate the corresponding frequencies. a. 5 s b. 12 s c. 220 ns
-
What does the amplitude of a signal measure? What does the frequency of a signal measure? What does the phase of a signal measure?
-
1) issued stock for $72,000 2) borrowed $41,000 from its bank 3) provided consulting services for $71,000 cash 4) paid back $31,000 of the bank loan 5) paid rent expense for $17,000 6) purchased...
-
Centurion Co. had the following accounts and balances at December 31: Account Cash Accounts Receivable Prepaid Insurance Supplies Accounts Payable T. Happy, Capital Service Revenue Salaries Expense...
-
Gretchen invests 6200 dollars in a mutual fund on January 1. On March 1, she learns that her fund balance is 3800 dollars, and she then withdraws 1500 dollars. On August 1, her fund balance is 7800...
The Seven Deadly Sins Of White Christian Nationalism A Call To Action - ISBN: 1538188317 - Free Book
Study smarter with the SolutionInn App