I want to add "OB" before every vowel. Sample input: "THIS IS A TEST" Sample output: "THOBIS OBIS OBA TOBEST" I have no idea why my code doesn't work:
public static String obify(String test) {
int x = 0;
while (x != -1) {
if (test.charAt(x) == 'A' || test.charAt(x) == 'E' || test.charAt(x) == 'I' || test.charAt(x) == 'O' || test.charAt(x) == 'U') {
test = test.replace(test.substring(x, x+1), "ob" + test.substring(x, x+1));
x += 3;
} else {
x++;
}
if (x >= test.length() - 1) {
x = -1;
}
}
return test;
}