我的程序读取一个单词文件,我试图打印以字母表的每个字母开头的单词的频率。但我的频率一直显示为“0”。谁能帮我?这是我的程序:
while (in.hasNext())
{
words.add(in.next());
}
in.close();
aFileReader.close();
for(int i = 0; i < chars.length - 1; i++)
{
int counter = 0;
for(int j = 0; j < words.size(); j++)
{
String temp = words.get(j);
String letter = temp.substring(0);
if(letter.equalsIgnoreCase(chars[i]))
counter++;
}
results += chars[i] + " = " + counter + "\n";
}
JOptionPane.showMessageDialog(null,results);