Reverse and remove letters in vowel positions Java Avg part-03
Reverse and remove letters in vowel positions:
Sharon does not like vowels. So she wants to remove vowels from any string. But her friend Jennie loves vowels and wants to retain vowels in as string. So both discuss and agree to the following condition.
- They will reverse the string value and then remove the letters in the positions of the vowels in the original string.
Help them by writing the program implementing the above condition.
import java.util.*;
public class Hello
{
static void replaceOriginal(String s, int n) {
char r[] = new char[n];
for (int i = 0; i < n; i++) {
r[i] = s.charAt(n - 1 - i);
if (s.charAt(i) != 'a' && s.charAt(i) != 'e' && s.charAt(i) != 'i'
&& s.charAt(i) != 'o' && s.charAt(i) != 'u') {
System.out.print(r[i]);
}
}
System.out.println("");
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
String s =sc.nextLine();
int n = s.length();
replaceOriginal(s, n);
}
}
Comments
Post a Comment