Incompatible Types String and Char

前端 未结 4 1982
挽巷
挽巷 2021-01-17 01:13

I\'m not sure why I\'m getting this error. I think the code in general is okay although I\'m sure there is a shorter way then using all the else ifs. The problem is it says

4条回答
  •  死守一世寂寞
    2021-01-17 01:41

    char is not String. Declare R2D2 as char

    char R2D2 = '';
    

    To check vowel make a method like below and reuse this method at for loop and count the vowel occurrence:

    static boolean isVowel(char ch) {
        ch = Character.toLowerCase(ch);
        if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
            return true;
        }
        return false;
     }
    

提交回复
热议问题