I need to replace every vowels in a given string with the same vowel, followed by the letter "v", followed by the vowel a second time. As an example: bad should become bavad, egg becomes evegg, doge becomes dovogeve, etc. The exercise explicitly states that it needs to be done with String.join() method. So far, I've come up with
this.
String string = "bad";
int length = string.length();
for (int i = 0; i < length; i++) {
char c = string.charAt(i);
if (isVowel(c)) {
string = String.join(c + "v" + c, string.split("" + c));
length += 2;
i += 2;
}
}
System.out.println(string);
The following isVowel method is a simple method to check whether a given char is a vowel or not
public static boolean isVowel(char c) {
return Arrays.asList('a', 'u', 'o', 'e', 'i').contains(c);
}
This solution is working fine for strings like bad, sad, step, etc. However, if I try it with aeiou, the output is avaeveiviovo instead of avaeveiviovouvu.