/**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
*
*this accounts for silent "e"s at the end of words, but not if they are in the middle of words, such as in "advertisement" or "likely"
*/
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++){//cycles through each word
int syl = 0;
String[] word = words[i].split("(?!^)");
for(int m = 0;m < word.length;m++){//cycles through each letter
boolean yVowel = false;
for(int j = 0;j < 5;j++){//checks with each vowel
boolean vowel = false;
if(word[m].equals(vowels[j]) == true){//checks for vowel
syl++;
vowel = true;
}
for(int n = 0;n < 5;n++){//checks if previous letter was a vowel
if(m > 0 && word[m-1].equals(vowels[n]) == true && vowel == true){
syl--;
}
}
if(word[m].equals("y") == true){//checks if the letter after y is a vowel
if(m < word.length - 2 && word[m+1].equals(vowels[j]) == false){
yVowel = false;
}else yVowel = true;
}
}
if(yVowel == true)//if letter after y is not a vowel, y is a vowel
syl++;
}
if(word[word.length-1].equals("e") == true)//if the last letter is an e, it does not count as a syllable
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.