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: 55% (9 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...
-
Does the use of inventory necessarily affect the amount of cash that is held by a corporation?
-
Crush Autosmashers can purchase a new electromagnet for moving cars at a cost of \($20,000.\) At the end of its useful life, the electromagnet will be worth \($1,000.\) If Crushs MARR is 12...
-
Kerns Book Warehouse distributes hardcover books to retail stores and extends credit terms of 2/10, n/30 to all of its customers. At the end of May, Kerns inventory consisted of books purchased for...
-
Put the argument from the following passage into standard form and construct an argument map diagram. There is no need to include unstated premises (assumptions) in your answer. Australia should not...
-
The following are typical questions that might appear on an internal control questionnaire for accounts payable. 1. Are monthly statements from vendors reconciled with the accounts payable listing?...
-
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...
-
Shade asked Dow to give him a check for $100 in return for Shades delivery the next day of a television set. Dow gave the check, but Shade never delivered the television set. Does Dow have a defense...
-
3 The following information is from Sander's Sync. Inc. 8 points REQUIRED a. Calculate goods available for sale b. Calculate cost of goods sold. Goods Available For Sale Merchandise Inventory March 1...
-
Can you provide a legal analysis over the issue of immigrant resources in schools. Provide a conclusion as to the resources needed to help with the improvement of immigrant youth in schools.
-
explain the journal entries .how can be it create ?
-
However, before they can be replaced the current machines must go through the proper retirement and transition process. As an IT professional you have been assigned to a team who is responsible for...
-
Janelle owns her own boutique and uses an Internet-connected device to run credit card transactions. In the event of a connection issue, she has documented specific procedures for how to process...
-
Headquartered in Toronto, Indigo Books & Music Inc. (TSX: IDG) is Canada's largest book retailer and the third largest in North America. Th e following information was taken from the management...
-
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?
-
A thin walled loop with a mass of 1.50 kg and with a radius of 10.0 cm rolls down a ramp with a height h=30.0 cm. If the loop starts from rest at the top of the ramp, what will its speed be when it...
-
Suppose there is a uniformly charged, infinitely tall metal surface. The surface charge density is -4.0 x 10-10 C/m2. An electron is 1.5 meters away from the wall and is launched directly at it with...
-
1. A basketball rolls down a ramp from rest with an acceleration of 2.5 m/s due to grav- up the ramp with an initial velocity of ity. At the same time, a tennis ball starts to roll 3.7 m/s and the...
Study smarter with the SolutionInn App