-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReverseVowel.java
More file actions
executable file
·36 lines (34 loc) · 1.21 KB
/
ReverseVowel.java
File metadata and controls
executable file
·36 lines (34 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Neel_Kapadia
*/
public class ReverseVowel {
public String reverseVowels(String s) {
StringBuilder sb = new StringBuilder(s);
int loc[] = new int[s.length()];
int count = 0;
for(int i = 0;i<s.length();i++){
if(s.charAt(i)=='a'||s.charAt(i)=='e'||s.charAt(i)=='i'||s.charAt(i)=='o'||s.charAt(i)=='u' || s.charAt(i)=='A'||s.charAt(i)=='E'||s.charAt(i)=='I'||s.charAt(i)=='O'||s.charAt(i)=='U'){
sb.append(s.charAt(i));
loc[count] = i;
count++;
}
}
String temp = sb.toString();
StringBuilder x = new StringBuilder(s);
for(int i = 0;i<count;i++){
x.replace(loc[i], loc[i]+1, temp.substring(temp.length() - i-1,temp.length()-i));
}
return x.toString();
}
public static void main(String[] args) {
ReverseVowel rv = new ReverseVowel();
String s = rv.reverseVowels("aA");
System.out.println(s);
}
}