import java.util.*;
public class Chardemo {
public static void main(String[] args) {
String str = "today is a special day";
HashMap<Character,Integer> ccMap = new HashMap<Character,Integer>();
char[] ac = str.toCharArray();
for(char c : ac) {
if(ccMap.get(c)==null)
ccMap.put(c, 1);
else {
int i=ccMap.get(c);
ccMap.put(c,i+1);
}
}
Set<Character> cs = ccMap.keySet();
for(char c : cs) {
System.out.println("'"+c+"'"+" : "+ccMap.get(c));
}
}
}
用java编 给定一字符串"today is a special day",长度为任意,要求找出其出现次数最多的字符及计算次数()
最新推荐文章于 2023-10-09 10:09:04 发布