I for the life of my cannot figure out why this code isnt working.
I want the integer trueLength to be the collective values of all the integers in the int array totals. For some reason I keep getting zero as the total even though totals contains numbers greater than zero.
Please help.
public int[] FrequencyFinder(File textfile) throws IOException
{
Scanner infile = new Scanner(textfile);
int trueLength = 0;
if(infile.hasNext())
{
file += infile.nextLine();
//System.out.println(file);
}
String[] alphabet = {"a","b","c","d","e","f","g","h","i","j","k","l"," m","n","o","p","q","r","s","t","u","v","w","x","y" ,"z"};
int[] totals = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0, trueLength};
for(int cc = 0; cc < file.length(); cc++)
{
for(int aa = 0; aa < alphabet.length; aa++)
{
if(file.substring(cc,cc + 1).equalsIgnoreCase(alphabet[aa]))
totals[aa] ++;
}
}
for(int x = 0; x < totals.length; x++)
{
trueLength += totals[x];
System.out.println(totals[x]);
}
return totals;