This one I almost have figured out (I believe). it is a program that takes a String in the main class and calls on a method to count the vowels inside the String. I then have to count each vowel (a,e,i,o,u) and input the total number of vowels (separately) into an array and return that array such that the output would be {1, 2, 1, 3, 1} or whatever it may be...any help?

public class VowelCount
{
    public static void main(String[] args)
        {
            String VC = "black banana republic boots";
            System.out.println(vowelCount(VC)); 
            
        }
        public static int[] vowelCount (String list)
        {
            int x = list.length();
            int[] aeiou = new int[4];
                                                     
            if(list.substring(0, x).equals("a"))
                aeiou[0]++;
            
            else if(list.substring(0, x).equals("e"))
                aeiou[1]++;

            else if(list.substring (0, x).equals("i"))
                 aeiou[2]++;

            else if(list.substring (0, x).equals("o"))
                 aeiou[3]++;
                     
            else if(list.substring(0, x).equals("u"))
                  aeiou[4]++;
                                
            return aeiou;
        }
    }

Recommended Answers

All 3 Replies

Use a for loop in you "vowelCount". Also, you can't print an array like that, use a for loop for that too. Look over the usage of "substring" again.

will they be nested for loops? I'm thinking not, but I don't know much about this stuff. and I will have to use a compound if statement, right? tryin to figure it out

Admin-You can delete this post. I figured it out
thanks for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.