Programming Examples
Java program to print only those words which contains all five vowels
Write a program to input a sentence and print only those words which has all the Five vowels present in it. (i.e. A,E,I,O,U) in a given sentence.
import java.util.*;
class AllVowels
{
public static void main(String arr[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter any String : ");
String str=sc.nextLine();
str=str.toUpperCase();
String word="";
str=str+" ";
for(int a=0;a<str.length();a++)
{
if(str.charAt(a)==' ')
{
if(word.indexOf('A')!=-1 && word.indexOf('E')!=-1 && word.indexOf('I')!=-1 && word.indexOf('O')!=-1 && word.indexOf('U')!=-1)
{
System.out.println(word);
}
word="";
}
else
{
word=word+str.charAt(a);
}
}
}
}
Output