-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSkipWord.java
More file actions
25 lines (21 loc) · 760 Bytes
/
SkipWord.java
File metadata and controls
25 lines (21 loc) · 760 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
package Recursion;
public class SkipWord {
private static String skip(String str) {
if (str.length() == 0)
return "";
if (str.startsWith("apple"))
return skip(str.substring(5));
return str.charAt(0) + skip(str.substring(1));
}
private static String skipAppNotApple(String str) {
if (str.length() == 0)
return "";
if (str.startsWith("app") && !str.startsWith("apple"))
return skipAppNotApple(str.substring(3));
return str.charAt(0) + skipAppNotApple(str.substring(1));
}
public static void main(String[] args) {
System.out.println(skip("aaerefapplesdfe"));
System.out.println(skipAppNotApple("apprefapplesdfe"));
}
}