Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package CollectionsHomework;
- import java.util.LinkedHashMap;
- import java.util.Map;
- import java.util.Scanner;
- public class Problem10CardFrequencies {
- public static void main(String[] args) {
- @SuppressWarnings("resource")
- Scanner input = new Scanner(System.in);
- String[] arrStr = input.nextLine().split("\\W+");
- Map<String, Integer> wordCounterMap = new LinkedHashMap<String, Integer>();
- Integer oldValue = 0;
- for (String wordCount : arrStr) {
- oldValue = wordCounterMap.get(wordCount);
- if (oldValue == null)
- oldValue = 0;// first time is always null
- wordCounterMap.put(wordCount, oldValue + 1);
- }
- for (Map.Entry<String, Integer> entry : wordCounterMap.entrySet()) {
- System.out.printf("%s - > %.2f%%", (String) entry.getKey(),
- (((double) entry.getValue() / arrStr.length) * 100));
- System.out.println();
- }
- }
- }
Add Comment
Please, Sign In to add comment