Advertisement
cd62131

InitialCharacter

Aug 1st, 2014
437
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.79 KB | None | 0 0
  1. import java.util.Map;
  2. import java.util.Map.Entry;
  3. import java.util.Scanner;
  4. import java.util.TreeMap;
  5.  
  6. public class InitialCharacter {
  7.   public static void main(String[] args) {
  8.     Scanner in = new Scanner(System.in);
  9.     Map<Character, Integer> acc = new TreeMap<Character, Integer>();
  10.     while (in.hasNext()) {
  11.       char c = in.next().charAt(0);
  12.       if (!Character.isAlphabetic(c))
  13.         continue;
  14.       if (!Character.isLowerCase(c))
  15.         c = Character.toLowerCase(c);
  16.       if (acc.get(c) == null)
  17.         acc.put(c, 0);
  18.       acc.put(c, acc.get(c) + 1);
  19.     }
  20.     in.close();
  21.     StringBuilder sb = new StringBuilder();
  22.     for (Entry<Character, Integer> e : acc.entrySet())
  23.       sb.append("" + e.getKey() + ": " + e.getValue() + "\n");
  24.     System.out.print(sb);
  25.   }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement