Question
In this program you will ask the user for a String, and then output the count of every word in that String in alphabetical order.
In this program you will ask the user for a String, and then output the count of every word in that String in alphabetical order. Youll need to use a HashMap to do this.
For example if the user entered:
Hello hello world
Youd print out hello: 2 world: 1
Since the word hello appeared twice and the word world appeared once.
HINT:
Use the provided printSortedHashMap method to print out the HashMap in alphabetical order.
import java.util.*;
public class WordCounts extends ConsoleProgram { public void run() { // Start here! } /* * This method takes a HashMap of word counts and prints out * each word and it's associated count in alphabetical order. * * @param wordCount The HashMap mapping words to each word's frequency count */ private void printSortedHashMap(HashMap
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started