Incompatible Types String and Char

前端 未结 4 1953
挽巷
挽巷 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:55

    If you want to fix the long if chain you can do something like this:

    if (anyOf(R2D2, "AaEeIiOoUuYy".toCharArray())
    

    and later have:

    private static boolean anyOf(char in, char[] items) {
        for (int i = 0; i < items.length; i++) {
            if (in == items[i])
                return true;
        }
        return false;
    }
    

提交回复
热议问题