-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemAllX.java
More file actions
35 lines (28 loc) · 722 Bytes
/
RemAllX.java
File metadata and controls
35 lines (28 loc) · 722 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
package coding;
public class RemAllX {
public static void main(String[] args) {
// System.out.println(Rem("moxxmodxxddx", "moxxdmodxxdx".length()-1));
System.out.println(duplicateChFormat("moooooods"));
}
public static String Rem(String str,int idx) {
if(idx==0) {
return str;
}
char ch=str.charAt(0);
if(ch=='x') {
return Rem(str.substring(1),idx-1)+ch;
}else {
return ch+Rem(str.substring(1),idx-1);
}
}
public static String duplicateChFormat(String str) {
if(str.length()==1) {
return str;
}
if(str.charAt(0)==str.charAt(1)) {
return str.charAt(0)+duplicateChFormat(str.substring(2));
}else {
return str.charAt(0)+duplicateChFormat(str.substring(1));
}
}
}