forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodingBat.java
More file actions
29 lines (26 loc) · 638 Bytes
/
CodingBat.java
File metadata and controls
29 lines (26 loc) · 638 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
/**
* CodingBat examples from Chapter 8.
*/
public class CodingBat {
public static String noX(String str) {
if (str.length() == 0) {
return "";
}
char c = str.charAt(0);
if (c == 'x') {
return noX(str.substring(1));
} else {
return c + noX(str.substring(1));
}
}
public int array11(int[] nums, int index) {
if (index >= nums.length) {
return 0;
}
if (nums[index] == 11) {
return 1 + array11(nums, index + 1);
} else {
return array11(nums, index + 1);
}
}
}