You used bitwise or (but each vowel is not some other vowel), I think you wanted a logical and. it
if (c != 'a' | c != 'e' | c != 'i' | c != 'o' | c != 'u')
should be something like
if (c != 'a' && c != 'e' && c != 'i' && c != 'o' && c != 'u')
You can also use a loop for-each
, and I would prefer StringBuilder
for creating a few immutable String
(s). Sort of,
StringBuilder sb = new StringBuilder();
for (char c : word.toCharArray()) {
if (c != 'a' && c != 'e' && c != 'i' && c != 'o' && c != 'u') {
sb.append(c);
}
}
System.out.println(sb);
, (- ),
if (!(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'))
, String
. - ,
System.out.println(word.replaceAll("[a|e|i|o|u]", ""));