//计算字符串中每个字母的个数
public class Demo5_caseCount {
public static void main(String[] args){
String s = "The only thing we have to fear itself";
s = s.toLowerCase();
char[] arr = s.toCharArray();
int[] count = new int[26];
for (int i = 97; i <= 122; i++) {
for (int j = 0; j < arr.length; j++) {
if ((char)i == arr[j]) {
count[i-97]++;
}
}
if (count[i-97] !=0) {
System.out.print((char)i + "(" + count[i-97] + ")");
}
}
}
}
|
|