-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhiCountBi.java
More file actions
65 lines (40 loc) · 1.09 KB
/
hiCountBi.java
File metadata and controls
65 lines (40 loc) · 1.09 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package coding;
public class hiCountBi {
public static void main(String[] args) {
String str="himofhisddsdshi";
// System.out.println(CountHi(str));
// System.out.println(RemoveHi(str));
System.out.println(RplaceHi(str));
// System.out.println("hisjkdhskjdhs".substring(0,2).equals("hi"));
}
public static int CountHi(String str) {
if(str.length()==1 || str.length()==0) {
return 0;
}
if(str.substring(0,2).equals("hi")) {
return CountHi(str.substring(2))+1;
}else {
return CountHi(str.substring(1));
}
}
public static String RemoveHi(String str) {
if(str.length()==1 || str.length()==0) {
return str;
}
if(str.substring(0,2).equals("hi")) {
return RemoveHi(str.substring(2));
}else {
return str.charAt(0)+RemoveHi(str.substring(1));
}
}
public static String RplaceHi(String str) {
if(str.length()==1 || str.length()==0) {
return str;
}
if(str.substring(0,2).equals("hi")) {
return "Bi"+RplaceHi(str.substring(2));
}else {
return str.charAt(0)+RplaceHi(str.substring(1));
}
}
}