deyanmalinov

04. Count Symbols - Print

Jun 1st, 2019
155
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package DPM;
  2.         import java.util.Map;
  3.         import java.util.Scanner;
  4.         import java.util.TreeMap;
  5.  
  6. public class Main {
  7.     public static void main(String[] args){
  8.         Scanner scan = new Scanner(System.in);
  9.         String line = scan.nextLine();
  10.         TreeMap<Character, Integer> chars = new TreeMap<>();
  11.         for (int i = 0; i < line.length(); i++) {
  12.             char simbol = line.charAt(i);
  13.             if (!chars.containsKey(simbol)){
  14.                 chars.put(simbol, 1);
  15.             }else {
  16.                 chars.put(simbol, chars.get(simbol) + 1);
  17.             }
  18.         }
  19.         for (Map.Entry<Character, Integer> characterIntegerEntry : chars.entrySet()) {
  20.             System.out.println(characterIntegerEntry.getKey() + ": "
  21.                                 + characterIntegerEntry.getValue() +" time/s");
  22.         }
  23.     }
  24. }
RAW Paste Data