- package com.heima.lianxi;
- import java.util.HashMap;
- import java.util.Scanner;
- public class Text3 {
- /**
- * @param args
- */
- public static void main(String[] args){
- String s = "aaabbbccccc";
- char[] arr = s.toCharArray();
- HashMap<Character, Integer> hm = new HashMap<Character, Integer>();
- for (char c : arr) {
- hm.put(c, !hm.containsKey(c)?1:hm.get(c)+1);
- }
- for (Character key : hm.keySet()) {
- System.out.println(key+" "+hm.get(key));
- }
- }
- }
复制代码 |
|