This page contains an archived post to the Java Answers Forum made prior to February 25, 2002.
If you wish to participate in discussions, please visit the new
Artima Forums.
Message:
Beginner Help -Counting Vowels
Posted by Patti Forman on February 09, 2002 at 8:05 PM
I'm a beginner. I need to count each vowel in the input string. What am I missing? Please help. import java.io.*; public class CountVowels
{ public static void main (String[] args) throws IOException { BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in)); System.out.println ("Enter a string: "); String inString = new String(stdin.readLine()); String stringToRead = inString; char aeiou; Character aCharacter; int aCount = 0; int eCount = 0; int iCount = 0; int oCount = 0; int uCount = 0; for (int count = 0;count < stringToRead.length(); count++) { aeiou= stringToRead.charAt(count); switch(aeiou) { case 'a': aCount = aCount + 1; case 'e': eCount = eCount + 1; case 'i': iCount = iCount + 1; case 'o': oCount = oCount + 1; case 'u': uCount = uCount + 1; } System.out.println ("Total A=" + aCount); System.out.println ("Total E=" + eCount); System.out.println ("Total I=" + iCount); System.out.println ("Total O=" + oCount); System.out.println ("Total U=" + uCount); } } }
Replies:
|