Write a program to in Java to enter a sentence form keyboard and also find all the words in that sentence with starting character as vowel

Write a program to enter a sentence form keyboard and also find all the words in  that sentence with starting character as vowel



import java.util.Scanner; class WordStarts_Vowel { public static void main(String[] args) { String str,wd=""; int len,i,pos=0,nv=0; char ch1,ch2; Scanner scr=new Scanner(System.in); System.out.println("Enter any line "); str=scr.nextLine(); str=str+" "; str=str.toLowerCase(); len=str.length(); System.out.println("Word starts with vowel...."); for(i=0;i<len;i++) { ch1=str.charAt(i); if(ch1==' ') { wd=str.substring(pos,i); ch2=wd.charAt(0); if(ch2=='a'||ch2=='e'||ch2=='i'||ch2=='o'||ch2=='u') { System.out.println(wd); nv=1; } pos=i+1; } } if(nv==0) System.out.println("No such word found that starts with vowel..."); } }

Output





Post a Comment

0 Comments