Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a COMPLETE static method named vowelCount that accepts a String as a param

ID: 3641513 • Letter: W

Question

Write a COMPLETE static method named vowelCount that accepts a String as a parameter and produces and returns an array of integers representing the counts of each vowel in the String.
The array returned by your method should hold 5 elements: the first is the count of As, the second is the count of Es, the third is the count of Is, the fourth is the count of Os, and the fifth is the count of Us.
You may assume that the string contains no uppercase letters.
For example, the call of vowelCount("black banana republic boots") should return an array containing {4, 1, 1, 2, 1}.

Explanation / Answer


import java.util.Arrays;

public class Vowel {
    
    static int[] vowelCount(String data) {
        
        int[]  vowelCount = new int[5];
        
        char[] dataArray= data.toCharArray();        
        for(int i=0;i<dataArray.length; i++) {
            
            char letter = dataArray[i];            
            
            if(letter=='a' || letter == 'A')
                vowelCount[0]=vowelCount[0]+1;
            if(letter=='e' || letter == 'E')
                vowelCount[1]=vowelCount[1]+1;            
            if(letter=='i' || letter == 'I')
                vowelCount[2]=vowelCount[2]+1;            
            if(letter=='o' || letter == 'O')
                vowelCount[3]=vowelCount[3]+1;            
            if(letter=='u' || letter == 'U')
                vowelCount[4]=vowelCount[4]+1;                        
        }
        
        return vowelCount;
    }


    public static void main(String[] args) {   
        int[]vowels = Vowel.vowelCount("black banana republic boots");        
        System.out.println(Arrays.toString(vowels));   
    }   
}


import java.util.Arrays;

public class Vowel {
    
    static int[] vowelCount(String data) {
        
        int[]  vowelCount = new int[5];
        
        char[] dataArray= data.toCharArray();        
        for(int i=0;i<dataArray.length; i++) {
            
            char letter = dataArray[i];            
            
            if(letter=='a' || letter == 'A')
                vowelCount[0]=vowelCount[0]+1;
            if(letter=='e' || letter == 'E')
                vowelCount[1]=vowelCount[1]+1;            
            if(letter=='i' || letter == 'I')
                vowelCount[2]=vowelCount[2]+1;            
            if(letter=='o' || letter == 'O')
                vowelCount[3]=vowelCount[3]+1;            
            if(letter=='u' || letter == 'U')
                vowelCount[4]=vowelCount[4]+1;                        
        }
        
        return vowelCount;
    }


    public static void main(String[] args) {   
        int[]vowels = Vowel.vowelCount("black banana republic boots");        
        System.out.println(Arrays.toString(vowels));   
    }   
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote