public class Demo01 {
public static void main(String[] args) {
String max = "woaiheima,heimahenlihai,womendajiadoushiheimachengxuyuan";
String min = "heima";
int count = getCount(max,min);
System.out.println("子串出现的次数是:"+count);
}
private static int getCount(String max, String min) {
int count = 0;
int index = max.indexOf(min);
while(index != -1){
count++;
max = max.substring(index + min.length());
index = max.indexOf(min);
}
return count;
} |
|