Check07B - final String REGEX =...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.io.*; import java.util.Scanner; //import java.io.File; //import java.io.FileNotFoundException; //import java.io.PrintStream; //USE THIS LINE WHEN INPUTTING IN COMMAND PROMPT LINUX: //words.txt //USE THIS LINE WHEN INPUTTING IN ECLIPSE IN LINUX: ///cs//home/cse03184/Projects/CSE1020/src/words.txt //USE THIS LINE WHEN INPUTTING IN ECLIPSE IN WINDOWS: /* E:\Documents and Settings\Dennis\My Documents\Downloads \York\Fall 2010\Programming\1020\Projects\CSE1020\src\words.txt */ public class Check07B { public static void main(String[] args) throws FileNotFoundException { System.out.println("Enter filename:"); Scanner fileIn = new Scanner(new File(new Scanner(System.in).nextLine())); int i = 0, avgSyllable = 0; while(fileIn.hasNextLine()) { int index = 0, count = 0, flag = 0; String buffer = fileIn.nextLine();
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: final String REGEX = "[aeiouyAEIOUY]+", E = "[eE]"; //If there's more than one syllable, then the fun begins. .. while (index < buffer.length()) { String store = String.valueOf(buffer.charAt(index)); if (store.matches(REGEX) && flag == 0) { //Increment count <-> last character is NOT e count += (index == buffer.length()-1 && store.matches(E)) ? 0 : 1; } flag = (store.matches(REGEX)) ? 1 : 0; index++; } //if word length is <= 2 characters or if the number of vowels is 1, //there is only one syllable. .. count = ((buffer.length() <= 2) || (buffer.split(REGEX)).length < 2) ? 1 : count; System.out.printf("%d\t%d\t%s%n", i, count, buffer); avgSyllable += count; i++; } System.out.printf("Average syllables per word = %.1f", (double) avgSyllable / i); fileIn.close(); } }...
View Full Document

Page1 / 2

Check07B - final String REGEX =...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online