Click to See Complete Forum and Search --> : Need help extracting vowels from Java


balooga97
October 3rd, 2009, 10:53 PM
I have to make a program in which I have to extract each vowel from a sentence the user inputs. I then have to show lines displaying the a count e count etc. and then a line showing the number of words. The other catch is it's supposed to show the number of vowels at zero if the user hits ok without putting in anything, but if cancel is hit it's supposed to show the summary of all the sentences that were input. As in if 'a' count was 1 then you hit ok then 'a' count was one again then you hit cancel and 'a' count showed 2. Anyway this is the code I have so but I get bogus results. If someone can help me it would be much appreciated.

public static void main (String[] args){
// Variables to be declared
String userInput;
String output;
int words=1;
int aCount=0, eCount=0, iCount=0, oCount=0, uCount=0;
do{
userInput=JOptionPane.showInputDialog("Input a Sentence");
userInput=userInput.toLowerCase();
if(userInput!=null);
{
for(int i=0 ; i<userInput.length(); i++)
{
char ch = userInput.charAt(i);
switch(ch){
case ' ': words++;
case 'a': aCount++;
case 'e': eCount++;
case 'i': iCount++;
case 'o': oCount++;
case 'u': uCount++;


output = "A count is: " + aCount + "\n";
output+= "E count is: " + eCount + "\n";
output+= "I count is: " + iCount + "\n";
output+= "O count is: " + oCount + "\n";
output+= "U count is: " + uCount + "\n";
output+= "Word count is:" + words + "\n";
;JOptionPane.showMessageDialog( (null), output, "Line Analysis (Ervin Williams)",
JOptionPane.INFORMATION_MESSAGE);
}
}
}

}while(userInput!=null); }}