如何数string里的字母数量
比如说一个string是“Chinese", 我要找出出现次数最多的字母,也就是e,请问这样的程序怎么写
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Count {
public static void main(String args[]) {
int maxCount = 0;
char maxChar = 'a';
String str = "Chinese";
for (char ch='a'; ch<='z'; ch++) {
int count=0;
Pattern p = (""+ch);
Matcher m = p.matcher(str.toLowerCase());
while(m.find())
count++;
if (count>maxCount) {
maxCount=count;
maxChar=ch;
}
}
System.out.println(出现次数最多的字母是:"+maxChar+" "+maxCount);
}