Hey, I'm writing a program about the Flesch Readability Index that is supposed to calculate the number or words, syllables, and sentences in a file. I have gotten the words counter to work, but I'm having a little difficulty with the syllables. The file I'm testing with just states "These cats are fast.", but I'm not getting a syllable count of 4. Hope you can help me figure this out! ^^
//count syllables; each group of adjacent vowels is one syllable; regal would be 2 //vowels = a,e,i,o,u,y //e at end of word is not a vowel //each word has at least one syllable //sentence = ends by ., :, ;, ?, or ! //index is computed by Index = 206.835 - 84.6*(num of syll/num of words) - 1.015*(num of words/num of sent) //rounded to nearest int //read file, compute index, print out educational level import java.io.*; import javax.swing.JFileChooser; import java.util.Scanner; public class Flesch { public static void main (String [] args) throws IOException { File datafile = null; JFileChooser chooser = new JFileChooser(); FileReader reader = null; String input = ""; String [] words; if(chooser.showOpenDialog(null)==JFileChooser.APPROVE_OPTION) datafile =chooser.getSelectedFile(); Scanner in = new Scanner(new FileReader(datafile)); String content = in.nextLine(); int totalWords = 0; int totalSyll = 0; //WORDS for (int i=0; i<content.length(); i++) { if (content.charAt(i)==' ') totalWords++; else if (content.charAt(i) == '.') totalWords++; else if (content.charAt(i) == ':') totalWords++; else if (content.charAt(i) == ';') totalWords++; else if (content.charAt(i) == '?') totalWords++; else if (content.charAt(i) == '!') totalWords++; else totalWords=totalWords; } System.out.println("There are " + totalWords + " words."); char syllableArray [] = {'a','e','i','o','u','y'}; //SYLLABLES for (int k=0; k<syllableArray.length; k++) { for (int i=0; i<=content.length(); i++) { if (content.charAt(i) == syllableArray[k] & content.charAt(i) == syllableArray[k]) totalSyll=totalSyll; if (content.charAt(i) == syllableArray[1]+' ') totalSyll=totalSyll; if (content.charAt(i) == syllableArray[k]) totalSyll++; else totalSyll=totalSyll; } } System.out.println("There are "+ totalSyll + " syllables."); } }