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

CCC Online Test 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz