Programming Examples

Java program to enter a sentence and print the words which starting with a vowel


Java program to enter a sentence and print the words which starting with a vowel

Solution

import java.util.*;
class Print_Vowel
{
   public static void main(String args[])
   {
        Scanner sc=new Scanner(System.in);            
        System.out.print("Enter any sentence: ");
        String s=sc.nextLine();
        s = s+" ";
        int l=s.length();
        int pos=0;
        char ch1, ch2;
        String w;
        for(int i=0; i<l; i++)
        {
            ch1 = s.charAt(i);
            if(ch1 == ' ')
            {
                w = s.substring(pos,i); // extracting words one by one
                ch2 = w.charAt(0);
                if(ch2=='A' || ch2=='E' || ch2=='I' || ch2=='O' || ch2=='U' ||
ch2=='a' || ch2=='e' || ch2=='i' || ch2=='o' || ch2=='u')
                {
                    System.out.print(w+"  ");
                }
                pos = i+1;
            }
        }
   }
}
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