
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)); } }
Describe me in deeply full detail of above program code how is make. this program output is like this
Enter string: the purpose of empty area of mind all that one Second Output: of empty area of all one the purpose mind that

In the above code, we have used StringTokenizer class that splits the string on the basis of " ".The method hasMoreTokens() of this class searches the words or tokens till the end of the string. The method nextToken() finds the word. If that word or token starts with a or e or i or o or u, then the word will store into the string vowels, otherwise the words will get stored into the string consonants. At last we have concatenated both the strings. This is the full description for your second output.
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.