Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package CharacterStatistic;
- import java.util.Map;
- import java.util.HashMap;
- class Statistic {
- Map<Character, Integer> Calc(String input) {
- Map<Character, Integer> stat = new HashMap<>();
- for (int i = 0; i < input.length(); i++) {
- char symbol = input.charAt(i);
- int count = stat.get(symbol) != null ? stat.get(symbol) : 0;
- count++;
- stat.put(symbol, count);
- }
- return stat;
- }
- void WriteStatistic(Map<Character, Integer> stat) {
- for (Character character: stat.keySet()) {
- System.out.println(character + " = " + stat.get(character));
- }
- }
- }
Add Comment
Please, Sign In to add comment