The program should tell user how many vowels occured on each word in a given string. The string was "Once upon a midnight dreary, while I pondered weak and weary."
The output generated by the codes below was:
Enter string(s): Once upon a midnight dreary, while I pondered weak and weary.
Once - 1
upon - 2
a - 0
midnight - 3
dreary - 2
while - 2
I - 0
pondered - 4
weak - 2
and - 1
weary - 2
some are correct, some are not.
import java.util.*;
import java.io.*;
public class part{
public static void main (String[]args) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader (System.in));
String sinput,sloop;
System.out.print ("Enter string(s): ");
sinput=br.readLine();
StringTokenizer soutput=new StringTokenizer(sinput,".,,,!,?, ");
while (soutput.hasMoreTokens()){
sloop=soutput.nextToken();
StringTokenizer soutput2=new StringTokenizer(sloop,"a,e,i,o,u,A,E,I,O,U");
System.out.println (sloop + " - " + soutput2.countTokens());
}
}
}