-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoveChar.java
More file actions
32 lines (27 loc) · 818 Bytes
/
MoveChar.java
File metadata and controls
32 lines (27 loc) · 818 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
// move x on the right side of a string
import java.util.*;
class Firstclass {
public static void move(String str , int idx , int count , String newStr) {
// str means oldString , idx means index , newstr means newString
// count is used to count number of x
if(idx == str.length()) {
for(int i = 0; i < count; i += 1) {
newStr += 'x';
}
System.out.print(newStr);
return;
}
char currChr = str.charAt(idx);
if(currChr == 'x') {
count++;
move(str, idx+1, count, newStr);
}
else {
newStr += currChr;
move(str, idx+1, count, newStr);
}
}
public static void main(String args[]) {
move("axbxxd", 0, 0, "");
}
}