Use string methods to find and count vowels in a string?

前端 未结 9 2116
青春惊慌失措
青春惊慌失措 2020-12-02 02:04

I have this problem for homework (I\'m being honest, not trying to hide it at least) And I\'m having problems figuring out how to do it.

Given the following declarat

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 02:33

    public class JavaApplication2 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here
        System.out.println("Enter some text");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String input = br.readLine().toLowerCase();
    
        char[] vowel = new char[]{'a', 'e', 'i', 'o', 'u'};
        int[] countVowel = new int[5];
        for (int j = 0; j < input.length(); j++) {
            char c =input.charAt(j);
            if(c=='a')
                countVowel[0]++;
            else if(c=='e')
                countVowel[1]++;
            else if(c=='i')
                countVowel[2]++;
            else if(c=='o')
                countVowel[3]++;
            else if(c=='u')
                countVowel[4]++;
    
    
        }
         for (int i = 0; i 
                                                            
提交回复
热议问题