Question: I d like to ask an expert In java please Determine the number of syllables in a sentence with an arbitrary number of words. Here
Id like to ask an expert
In java please
Determine the number of syllables in a sentence with an arbitrary number of words.
Here are some rules you are required to use for determining the number of syllables in a word. There are other more complicated cases not described in the steps below. Ignore those cases for this assignment.
StepDo toUpperCaseor toLowerCaseto the input at the beginning so you have less comparisons
Step Count the number of vowels including y aeio uy
Step Subtract for every instance of two vowels being next to each other.
Step Subtract if there's a vowel at the end of the word EXCEPT Y
For example the word feline is syllables
We determine that by taking the number of vowels we check for any vowels next to each other nonethen we see if there are any vowels at the end of the word The syllable count or
Example
Input
I am tired
Output
Thank you
This is my current code
import java.util.Scanner;
public class Main
public static void mainStringargs
Scanner scnr new ScannerSystemin;
String sentence I am tired";
int totalSyllables countSyllablesInSentencesentence;
System.out.printlntotalSyllables;
public static int countSyllablesInSentenceString sentence
Convert the entire sentence to lowercase to reduce comparisons
sentence sentencetoLowerCase;
Stringwords sentencesplits; Split the sentence into words
int totalSyllables ;
for String word : words
totalSyllables countSyllablesInWordword;
return totalSyllables;
public static int countSyllablesInWordString word
Define vowels
String vowels aeiouy;
int syllableCount ;
boolean lastCharWasVowel false;
Special case for oneletter words
if wordlength&& vowels.indexOfwordcharAt
return ;
for int i ; i wordlength; i
char currentChar wordcharAti;
if vowelsindexOfcurrentChar
Count the first vowel or a nonconsecutive vowel
if i lastCharWasVowel
syllableCount;
lastCharWasVowel true;
else
lastCharWasVowel false;
Handle silent eegin words like "made" or "taste"
if wordendsWithe&& syllableCount && vowels.indexOfwordcharAtwordlength
syllableCount;
Ensure at least syllable for any word
return Math.maxsyllableCount;
And these are the things Im getting wrong
Input
this is hard
Your output
Expected output
Input
dylan is hungry
Your output
Expected output
Input
good food
Your output
Expected output
Input
hi
Your output
Expected output
Thank you
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
