public class AssignmentChapter9
{
public static void main(String[] args)
{
String words = Input.getString("Please enter a series of words with the spaces omitted.");
String alphabet = "abcdefghijklmnopqrstuvwxyz";
String inputWords = words.toLowerCase();
int lcount[] = new int[26];
char var1;
char var2;
for(int x = 0; x <= words.length(); x++)
{
var1 = words.charAt(x);
for(int y = 0; y < 27; y++)
{
var2 = alphabet.charAt(y);
if(var1 == var2)
{
lcount[y] += 1;
}
}
}
for(int z = 0; z < 27; z++)
{
System.out.println("Letter " + alphabet.charAt(z + 1) + " count = " + lcount[z]);
}
}
}
我一直在尝试用java编写一个程序来确定字母表中每个字符在给定字符串中出现的次数。我能够成功编译程序,但是在用户输入完成后,它给出了一个越界异常。任何帮助,将不胜感激。