标题: 计算字符串中每个字母的个数 [打印本页] 作者: wx_pmVIrag6 时间: 2016-8-5 22:21 标题: 计算字符串中每个字母的个数 //计算字符串中每个字母的个数
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]++;
}
}