/* Given a string, reverse only vowels in it; leaving rest of the string as it is.
Input : abcdef
Output : ebcdaf */
import java.io.*;
import java.util.*;
public class VowelReverse {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
String vowels = "";
String ans = "";
int arr[] = new int[str.length()];
for(int i=0;i<str.length();i++) {
if(str.charAt(i)=='a' || str.charAt(i)=='e' || str.charAt(i)=='i' || str.charAt(i)=='o' || str.charAt(i)=='u') {
vowels+=str.charAt(i);
arr[i]=1;
}
}
String revVowels = new StringBuffer(vowels).reverse().toString();
int j=0;
for(int i=0;i<str.length();i++) {
if(arr[i]!=1) {
ans+=str.charAt(i);
}
else {
ans+=revVowels.charAt(j);
j++;
}
}
System.out.println(ans);
}
}
Input : abcdef
Output : ebcdaf */
import java.io.*;
import java.util.*;
public class VowelReverse {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.next();
String vowels = "";
String ans = "";
int arr[] = new int[str.length()];
for(int i=0;i<str.length();i++) {
if(str.charAt(i)=='a' || str.charAt(i)=='e' || str.charAt(i)=='i' || str.charAt(i)=='o' || str.charAt(i)=='u') {
vowels+=str.charAt(i);
arr[i]=1;
}
}
String revVowels = new StringBuffer(vowels).reverse().toString();
int j=0;
for(int i=0;i<str.length();i++) {
if(arr[i]!=1) {
ans+=str.charAt(i);
}
else {
ans+=revVowels.charAt(j);
j++;
}
}
System.out.println(ans);
}
}
Comments
Post a Comment