Guest User

Untitled

a guest
Feb 25th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. package CharacterStatistic;
  2.  
  3. import java.util.Map;
  4. import java.util.HashMap;
  5.  
  6. class Statistic {
  7. Map<Character, Integer> Calc(String input) {
  8. Map<Character, Integer> stat = new HashMap<>();
  9.  
  10. for (int i = 0; i < input.length(); i++) {
  11. char symbol = input.charAt(i);
  12. int count = stat.get(symbol) != null ? stat.get(symbol) : 0;
  13. count++;
  14. stat.put(symbol, count);
  15. }
  16.  
  17. return stat;
  18. }
  19.  
  20. void WriteStatistic(Map<Character, Integer> stat) {
  21. for (Character character: stat.keySet()) {
  22. System.out.println(character + " = " + stat.get(character));
  23. }
  24. }
  25. }
Add Comment
Please, Sign In to add comment