Java题(统计字符串中字母的个数)

使用下列方法头编写一个方法,统计字母在字符串中出现的个数。Public static int countLetters(String s)

public static int countLetters(String s) {String str =s; while (!"".equals(str)) {
String c = str.substring(0, 1);
String tempStr = str.replace(c, "");
System.out.println(c + " : " + (str.length() - tempStr.length()));
str = tempStr;
}
温馨提示:答案为网友推荐,仅供参考
相似回答