这就是我所拥有的,但它不起作用,这让我感到困惑。如果您向下滚动,我评论了某人发布了我遇到的确切问题以及我正在尝试做的事情。我在想也许问题是我生成随机字符的代码:
public void add (char fromChar, char toChar){
Random r = new Random(); //creates a random object
int randInt;
for (int i=0; i<charArray.length; i++){
randInt = r.nextInt((toChar-fromChar) +1);
charArray[i] = (char) randInt; //casts these integers as characters
}
}//end add
public int[] countLetters() {
int[] count = new int[26];
char current;
for (int b = 0; b <= 26; b++) {
for (int i = 97; i <= 123; i++) {
char a = (char) i;
for (int ch = 0; ch < charArray.length; ch++) {
current = charArray[ch];
if (current == a) {
count[b]++;
}
}
}
}
return count;
}