Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Map;
- import java.util.Map.Entry;
- import java.util.Scanner;
- import java.util.TreeMap;
- public class InitialCharacter {
- public static void main(String[] args) {
- Scanner in = new Scanner(System.in);
- Map<Character, Integer> acc = new TreeMap<Character, Integer>();
- while (in.hasNext()) {
- char c = in.next().charAt(0);
- if (!Character.isAlphabetic(c))
- continue;
- if (!Character.isLowerCase(c))
- c = Character.toLowerCase(c);
- if (acc.get(c) == null)
- acc.put(c, 0);
- acc.put(c, acc.get(c) + 1);
- }
- in.close();
- StringBuilder sb = new StringBuilder();
- for (Entry<Character, Integer> e : acc.entrySet())
- sb.append("" + e.getKey() + ": " + e.getValue() + "\n");
- System.out.print(sb);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement