The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
February 2002

Advertisement

Advertisement

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:

Need Default after Switch to give total other letters

Posted by Patti on February 12, 2002 at 1:07 PM

Beginner here. In my program to count up each vowel abd total, I need a default line that counts the other letters as one total. 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 aeiouAEIOU;

int aCount = 0;
int eCount = 0;
int iCount = 0;
int oCount = 0;
int uCount = 0;
int otherletters = 0;
for (int count = 0;count < stringToRead.length();
count++) {

aeiouAEIOU= stringToRead.charAt(count);

switch(aeiouAEIOU) {
case 'a':
aCount = aCount + 1;
break;
case 'A':
aCount = aCount + 1;
break;
case 'e':
eCount = eCount + 1;
break;
case 'E':
eCount = eCount + 1;
break;
case 'i':
iCount = iCount + 1;
break;
case 'I':
iCount = iCount + 1;
break;
case 'o':
oCount = oCount + 1;
break;
case 'O':
oCount = oCount + 1;
break;
case 'u':
uCount = uCount + 1;
break;
case 'U':
uCount = uCount + 1;
break;

}
}
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);


Default:
System.out.println ("Total Other=");



}
}




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us