Skip to content

Commit d5d73ac

Browse files
committed
recursion 2
1 parent e0f9159 commit d5d73ac

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
public class Recursion2_RemoveX {
3+
4+
public static String removeX(String str) {
5+
6+
if(str.length()==0) {
7+
return str;
8+
}
9+
10+
if(str.charAt(0)=='x') {
11+
return removeX(str.substring(1,str.length()));
12+
}
13+
else {
14+
return str.charAt(0) + removeX(str.substring(1,str.length()));
15+
}
16+
17+
}
18+
19+
public static void main(String[] args) {
20+
21+
String str = "xbxa";
22+
System.out.println(removeX(str));
23+
24+
}
25+
26+
}

0 commit comments

Comments
 (0)