I am getting a lightbulb on NetBeans saying "The if statement is redundant"
I want to know how these two are equal to one another
public boolean isVowel(char in)
{
char temp = Character.toLowerCase(in);
if (temp == 'a' || temp == 'e' || temp == 'i' || temp == 'o' || temp == 'u')
{
return true;
}
else
{
return false;
}
}
and
public boolean isVowel(char in)
{
char temp = Character.toLowerCase(in);
return temp == 'a' || temp == 'e' || temp == 'i' || temp == 'o' || temp == 'u';
}
I can see how it would return true if one of the vowels matches with temp. However, I am not seeing how it would return false. Would it simply just return false if none of the conditions are met?
Solved: I was looking at the problem the wrong way. For it to return false, each conditional statement would have to be false. Ideally it would return false if the return statement was equivalent to:
return false || false || false || false || false;
and true if any one condition is met
return false || false || false || false || true;
Thanks you guys, it really helped.
Aucun commentaire:
Enregistrer un commentaire