syllableCount

/**counts the syllables *josh wang *twelve october anno domini two-thousand seventeen * *a syllable is a vowel sound (or diphthong) with its surrounding consonants *a raspberry is a very tart fruit *a sosig is not a fruit * */ import java.util.*; public class syllableCount{ String[] words = {"cat", "hello", "world", "tennis", "episcopal", "count", "learn", "denise", "state", "statement", "fruit", "calculation", "spite", "spiteful", "reservation", "late", "lately", "extreme", "expensive"}; //19 elements String[] vowels = {"a","e","i","o","u"}; public syllableCount(){ doTheThing(); } public void doTheThing(){ for(int i = 0;i < words.length;i++){ int syl = 0; String[] word = words[i].split("(?!^)"); for(int m = 0;m < word.length;m++){ boolean yVowel = false; for(int j = 0;j < 5;j++){ boolean vowel = false; if(word[m].equals(vowels[j]) == true){ syl++; vowel = true; } for(int n = 0;n < 5;n++){ if(m > 0 && word[m-1].equals(vowels[n]) == true && vowel == true){ syl--; } } if(word[m].equals("y") == true){ if(m < word.length - 2 && word[m+1].equals(vowels[j]) == false){ yVowel = true; }else yVowel = true; } } if(yVowel == true) syl++; } if(word[word.length-1].equals("e") == true) syl--; System.out.println(syl + " " + words[i]); } } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.