Java program to find total Vowels of words from a given sentence.
public class VowelFromWord
{
public static void main(String args[])
{
// Sentence taken
String st="the quick brown dog jumpe over a lazy fox";
String word=""; // initialize the variable word
int i,l,l1,j,v;
char ch,ch1;
st=st+" ";
l=st.length();
for(i=0;i<l;i++)
{
v=0;
ch=st.charAt(i);
if(ch!=' ')
{
word=word+ch; // picking the word
}
else
{
l1=word.length();
for(j=0;j<l1;j++)
{
ch1=word.charAt(j);
if(ch1=='a' || ch1=='e' || ch1=='i'|| ch1=='o' || ch1=='u')
v++; // calculating the vowel in the picked word
}
// printing the word with vowel
System.out.println(word+" contain " + v+" vowel");
word="";
}
}
}
}
Output
quick contain 2 vowel
brown contain 1 vowel
dog contains 1 vowel
jump contains 2 vowel
over contain 2 vowel
a contain 1 vowel
lazy contain 1 vowel
fox contains 1 vowel
No comments:
Post a Comment