Q:

Print the number of unique vowels in a string, Java

I need to find the number of distinct vowels. I came up with the code below but it can't make distinction between same vowels:
public static int count_Vowels(String str) {
    str = str.toLowerCase();
    int count = 0;
    for (int i = 0; i < str.length(); i++) {
        if (str.charAt(i) == 'a' || str.charAt(i) == 'e' || str.charAt(i) == 'i'
                || str.charAt(i) == 'o' || str.charAt(i) == 'u') {
            count++;
        }
    }
    return count;
}

A:

I would start with five variables (one for each vowel) set to 0, iterate the characters in the input and set the corresponding variable to 1 if I find a match, and simply return the accumulated value of said variables. Like,
public static int count_Vowels(String str) {
    int a = 0, e = 0, i = 0, o = 0, u = 0;
    for (char ch : str.toLowerCase().toCharArray()) {
        if (ch == 'a') {
            a = 1;
        } else if (ch == 'e') {
            e = 1;
        } else if (ch == 'i') {
            i = 1;
        } else if (ch == 'o') {
            o = 1;
        } else if (ch == 'u') {
            u = 1;
        }
    }
    return a + e + i + o + u;
}

