Given a sentence the task is to find the number of vowels present in each word of the sentence. Also print the word along with the vowel count.
Java
import java.util.*;
public class WordVowelCount
{
public static void main(String Args[])
{
int l=0,count=0;
String str="",word="";
char ch=' ';
Scanner sc=new Scanner(System.in);
System.out.print("Enter a sentence: ");
str=sc.nextLine();
str=str.trim();
str=str+" ";
l=str.length();
for(int i=0;i<l;i++)
{
ch=str.charAt(i);
if(ch==' ')
{
System.out.println(word + ": "+ count);
count=0;
word="";
}
else
{
word=word+ch;
if(ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U'||ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
{
count++;
}
}
}
}
}Java