my program reads a file of words and im trying to print the frequency of how many words start with each letter of the alphabet. but my frequency keeps coming out as "0". Can anyone help me? this is my program:
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);