/**
* The quest to make a program that tells the number of Syllabels was one of difficulty. Many attempts were made but all have failed.
* I struggled with all the different exceptions for syllables that exist within the english language. I tried implementing a system when the last syllabel is e but it didnt really work.
*/
public class Syllables
{
public static void main (String[] args) {
System.out.println(countVowels("created"));
}
public static int countVowels (String arg) {
String prevChar = "z";
int one = 0;
int two = 1;
int count = 0;
while (two < arg.length()) {
System.out.println(arg.substring(one,two));
if (arg.substring(one,two).equals("a") || arg.substring(one,two).equals("e") || arg.substring(one,two).equals("i") || arg.substring(one,two).equals("o") || arg.substring(one,two).equals("u")) {
if (prevChar.equals("a") || prevChar.equals("e") | prevChar.equals("i") || prevChar.equals("o") || prevChar.equals("u")) {
//NOTHING
} else {
count += 1;
}
}
/* if (lastChar.equals("e")) {
count -= 1;
if (arg.substring(arg.length() - 1, arg.length() - 1).equals("l")) {
String prevTwo = arg.substring(arg.length() - 2, arg.length() + 1);
} else {
count += 1;
}
}
}
*/
prevChar = arg.substring(one,two);
one += 1;
two += 1;
}
return count;
}
}
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.