This Java code is giving me trouble:
String word = <Uses an input>
int y = 3;
char z;
do {
z = word.charAt(y);
if (z!='a' || z!='e' || z!='i' || z!='o' || z!='u')) {
for (int i = 0; i==y; i++) {
wordT = wordT + word.charAt(i);
} break;
}
} while(true);
I want to check if the third letter of word is a non-vowel, and if it is I want it to return the non-vowel and any characters preceding it. If it is a vowel, it checks the next letter in the string, if it's also a vowel then it checks the next one until it finds a non-vowel.
Example:
word = Jaemeas then wordT must = Jaem
Example 2:
word=Jaeoimus then wordT must =Jaeoim
The problem is with my if
statement, I can't figure out how to make it check all the vowels in that one line.
z!='a'||z!='e'...
will always fail.z
can't be equal toa
ande
(and so on) at the same time. Try&&
instead. – Unproductivey
vowel ! And I'm a little bit confused about yourif
condition : every letter is differeent froma
ORe
etc... UseAND
operator instead – Ashur||
theOR
logic? I guess that statement will pass. – WorldlingAND
not anOR
. However if you see the answer I selected the"AEIOUaeiou".indexOf(z) <0
is a much cleaner solution – Technique