For my program I am trying to find out the percentage of words in my data file that are 3 letters long. Though whenever I run the program I receive an error stating that you can not divide by 0. I increase my variable wordCount by 1 every time my loop runs, yet for some reason my program recognizes it as 0. Can anybody assist me as to how I am recieving this error?
int threeLetters=0;
int wordCount=0;
while(inFile.hasNextLine()){
wordCount= wordCount +1;
String line = inFile.nextLine();
String[] word =line.split(" ");
int wordLength = word.length;
if (wordLength == 3){
threeLetters= threeLetters+1;
}
}
double percentage = wordCount/threeLetters;// error recieved here
This is the text file the program is reading from
Good morning life and all
Things glad and beautiful
My pockets nothing hold
But he that owns the gold
The sun is my great friend
His spending has no end
Hail to the morning sky
Which bright clouds measure high
Hail to you birds whose throats
Would number leaves by notes
Hail to you shady bowers
And you green fields of flowers
Hail to you women fair
That make a show so rare
In cloth as white as milk
Be it calico or silk
Good morning life and all
Things glad and beautiful
smallerInt / biggerInt = 0.0