
Write a program to accept a sentence. Print all the words that starts with vowel and end with a consonant. e.g. input by user "the purpose of education is to replace an empty mind with an open one" Ist output of open one education empty is an an the purpose to replace mind with
and Second IInd output of education is an empty an open one the to replace mind with

Java accept sentence from user and print all word starts with vowel and end with consonant
import java.util.*;
class StringExample6
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.println("Enter string:");
String str=input.nextLine();
StringTokenizer stk=new StringTokenizer(str);
String vowels="",consonants="";
while(stk.hasMoreTokens()){
String token=stk.nextToken();
if(token.startsWith("a")||token.startsWith("e")||token.startsWith("i")||token.startsWith("o")||token.startsWith("u")){
vowels+=token+" ";
}
else if(!token.startsWith("a")||!token.startsWith("e")||!token.startsWith("i")||!token.startsWith("o")||!token.startsWith("u")){
consonants+=token+" ";
}
}
System.out.println("Second Output: "+vowels.concat(consonants));
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.