I'm making a program that counts the number of vowels in a phrase that was assigned by my teacher. To do this I have made a for-loop that in theory should check each character for being a, then e, the i, and so on before moving on to the next character. For some reason though nothing in the for-loop works. The build output states that everything is fine, but the for-statements aren't functioning properly. I know that t actually is the correct letter because I printed what t was but the for loop still won't work. What confuses me is the build output is fine, so it must be a logic error, but I can't find where it is. Here is the code:
for (i = 0; i != phrase.length(); i++) {
String t = phrase.substring(i, i + 1);
if (t == "a") {
count++;
System.out.println(count);
}
if (t == "e") {
count++;
}
if (t == "i") {
count++;
}
if (t == "o") {
count++;
}
if (t == "u") {
count++;
}
}
System.out.println(count);
Many thanks to anyone who can help me!