Given a sentence ending with ‘.’ or ‘?’ or ‘!’ the task is to only print the words that start as well as end with vowels.
Example: The office computers are not connected to internet. The program should print the words start and end with vowels. That is “office” and “are“.
Java
import java.util.*;
class WordVowelSE
{
public static void main(String args[])
{
String str="",wrd="";
int l=0;
char ch=' ',sCh=' ',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 and ending with vowels:-");
for(int i=0;i<l;i++)
{
ch=str.charAt(i);
if(ch==' '||ch=='.'||ch=='?'||ch=='!')
{
sCh=wrd.charAt(0);
eCh=wrd.charAt(wrd.length()-1);
if((sCh=='A'||sCh=='E'||sCh=='I'||sCh=='O'||sCh=='U'||sCh=='a'||sCh=='e'||sCh=='i'||sCh=='o'||sCh=='u')&&
(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