I've written a code which is intended to insert string "av" before any vowel in the given String, which is not be preceded by another vowel.
Consider the String as an input:
"aadeleo"
After adding "av" before each and every vowel which are not preceded by another vowel, the output should be:
"avaadavelaveo"
But my code produces:
"avaavadavelaveavo"
My code:
public class Main {
public static void main(String[] args) {
String st = "aadeleo";
String word = "";
int l = st.length();
char c, c2;
for (int i = l - 1; i > 0; i--) {
c = st.charAt(i);
c2 = st.charAt(i - 1);
if ((c == 'a' || c == 'e' ||
c == 'i' || c == 'o' ||
c == 'u') && (c2 != 'a' || c2 != 'e' ||
c2 != 'i' || c2 != 'o' ||
c2 != 'u')) {
word = "av" + c + word;
} else
word = c + word;
}
c = st.charAt(0);
if (c == 'a' || c == 'e' ||
c == 'i' || c == 'o' ||
c == 'u')
word = "av" + c + word;
else
word = c + word;
System.out.println(word);
}
}