-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverseVowels.java
More file actions
35 lines (29 loc) · 825 Bytes
/
reverseVowels.java
File metadata and controls
35 lines (29 loc) · 825 Bytes
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
import java.util.*;
public class reverseVowels{
public static void main(String args[]){
String s="hello";
String reverse=reverse_vowels(s);
System.out.println(reverse);
}
public static String reverse_vowels(String s) {
if(s == null || s.length()==0) return s;
String vowels = "aeiouAEIOU";
char[] chars = s.toCharArray();
int start = 0;
int end = s.length()-1;
while(start<end){
while(start<end && !vowels.contains(chars[start]+"")){
start++;
}
while(start<end && !vowels.contains(chars[end]+"")){
end--;
}
char temp = chars[start];
chars[start] = chars[end];
chars[end] = temp;
start++;
end--;
}
return new String(chars);
}
}