我试图为每个字符(A 到 Z 和 a 到 z)编写一个分配计数的方法。到目前为止我所拥有的是
public int[] getLetterDistribution() {
int[] distribution = new int[26];
return distribution;
}
我目前的尝试是:
public int[] getLetterDistribution() {
int[] distribution = new int[26];
for (int count = 0; count < distribution.length; count++) {
String current = distribution[count];
char[] letters = current.toCharArray();
for (int count2 = 0; count2 < letters.length; count2++) {
char lett = letters[count2];
if ( (lett >= 'A') & (lett <= 'Z') ) {
letterCount[lett - 'A']++;
}
}
}
for (char count = 'a'; count <= 'z'; count++) {
System.out.print(count + ": " +
letterCount[count - 'a'] +" ");
}
System.out.println();
return distribution;
}
但我不断收到错误。对于那些java高手来说,一个彻底的解释会很棒。有谁知道我在这里做错了什么?