- public static void main(String[] args){
- // TODO 自动生成的方法存根
- String str ="abcdekka27qoq";
- System.out.println(charCount(str));
- }
- public static String charCount(String str){
- char[] chs = str.toCharArray();
- Map<Character,Integer> m = new TreeMap<Character,Integer>();
- int count =0;
- for(int x=0;x<chs.length;x++){
- if(chs[x]>='a'&&chs[x]<='z'||chs[x]>='A'&&chs[x]<='Z'){
- Integer value = m.get(chs[x]);
- if(value!=null)
- count=value;
- count++;
- m.put(chs[x], count);
- count =0;
- }
- }
复制代码
代码这 Integer value = m.get(chs[x]);
if(value!=null)
count=value;
count++;
m.put(chs[x], count);
count =0;
的思想 谢谢!!! |