Given a sentence ending with ‘.’ or ‘?’ or ‘!’ the task is to only print the words that end with vowels.
Example: The office computers are not connected to internet. The program should print the words that end with vowels. That is “The“, “office“, “are” and “to“.
Java
import java.util.*;
class WordVowelE
{
public static void main(String args[])
{
String str="",wrd="";
int l=0;
char ch=' ',eCh=' ';
Scanner sc=new Scanner(System.in);
System.out.println("Enter a sentence ending with '.' or '?' or '!'");
str=sc.nextLine();
str=str.trim();
l=str.length();
ch=str.charAt(l-1);
if(!(ch=='.'||ch=='?'||ch=='!'))
{
System.out.println("Error! Sentence must be terminated by punctuation");
System.exit(1);
}
System.out.println("Words starting with vowels:-");
for(int i=0;i<l;i++)
{
ch=str.charAt(i);
if(ch==' '||ch=='.'||ch=='?'||ch=='!')
{
eCh=wrd.charAt(wrd.length()-1);
if(eCh=='A'||eCh=='E'||eCh=='I'||eCh=='O'||eCh=='U'||eCh=='a'||eCh=='e'||eCh=='i'||eCh=='o'||eCh=='u')
{
System.out.println(wrd);
}
wrd="";
}
else
{
wrd=wrd+ch;
}
}
}
}Java