-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupper_case_conversion.java
57 lines (50 loc) · 1.23 KB
/
upper_case_conversion.java
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//{ Driver Code Starts
//Initial Template for Java
import java.io.*;
import java.util.*;
class GFG
{
public static void main(String args[])throws IOException
{
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0)
{
String s;
s = sc.next();
Solution ob = new Solution();
System.out.println(ob.modify(s));
}
}
}
// } Driver Code Ends
//User function Template for Java
class Solution
{
String modify (String s)
{
// your code here
ArrayList<Character> charList=new ArrayList<>();
String res="";
for(int i=0;i<s.length();i++)
{
char ch=s.charAt(i);
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')
{
charList.add(ch);
}
}
Collections.reverse(charList);
for(int i=0;i<s.length();i++)
{
char ch=s.charAt(i);
if(ch == 'a' ||ch == 'e' ||ch == 'i' ||ch == 'o' ||ch == 'u'){
res += charList.get(0);
charList.remove(0);
}else{
res += ch;
}
}
return res;
}
}