Link to home
Start Free TrialLog in
Avatar of msheppard74
msheppard74Flag for United States of America

asked on

How to select non-vowel characters

I have the following code that checks for lower case vowels in a string, counts them and prints them. How could I ammend this code to count any character that is not A, I, E, O, U, a, i, e, o or u?

Thanks!
Avatar of msheppard74
msheppard74
Flag of United States of America image

ASKER

Here is the code

import java.util.*;

public class SheppardPP515
{

      public static void main (String[] args)
      {
      
            int a = 0;
            int e = 0;
            int i = 0;
            int o = 0;
            int u = 0;
            int nonVowels = 0;
            
            String message;
            
            Scanner scan = new Scanner (System.in);
            
            System.out.println ("enter your string now:");
            
            message = scan.nextLine();
            
            
                  for (int n = 0; n < message.length(); n++)
                        {
                              if (message.charAt(n) == 'a')
                                          a++;
                              if (message.charAt(n) == 'e')
                                          e++;
                              if (message.charAt(n) == 'i')
                                          i++;
                              if (message.charAt(n) == 'o')
                                          o++;
                              if (message.charAt(n) == 'u')
                                          u++;            
                        }
                                    
                  if (a != 0)
                        System.out.println("There are " + a + " a's.");
                  if (e != 0)      
                        System.out.println("There are " + e + " e's.");
                  if (i != 0)      
                        System.out.println("There are " + i + " i's.");
                  if (o != 0)      
                        System.out.println("There are " + o + " o's.");
                  if (u != 0)      
                        System.out.println("There are " + u + " u's.");
ASKER CERTIFIED SOLUTION
Avatar of msheppard74
msheppard74
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial