forked from LaunchCodeEducation/java-web-dev-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacterCount.java
More file actions
25 lines (21 loc) · 1.06 KB
/
CharacterCount.java
File metadata and controls
25 lines (21 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package org.launchcode;
import java.util.HashMap;
import java.util.Map;
public class CharacterCount {
public static void main(String[] args) {
String hiddenFig = "If the product of two terms is zero then common sense says at least one of the two terms has to be zero to start with. So if you move all the terms over to one side, you can put the quadratics into a form that can be factored allowing that side of the equation to equal zero. Once you’ve done that, it’s pretty straightforward from there.";
char[] charHiddenFig = hiddenFig.toCharArray();
HashMap<Character, Integer> counts = new HashMap<>();
for (char letter : charHiddenFig) {
if (counts.containsKey(letter)) {
counts.put(letter, counts.get(letter) + 1);
} else {
counts.put(letter, 1);
}
}
for (Map.Entry<Character, Integer> count : counts.entrySet()) {
System.out.println(count.getKey() + ": " + count.getValue());
}
input.close();
}
}