//计算大字符串中小字符串的个数
public class Demo2_zifuchuanCount {
public static void main(String[] args){
String max = "heimademeizi,heimadeniv,heimadeshuaige,heimadeche";
String min = "heima";
int count = 0;
while(true) {
int index = max.indexOf(min);
if (index != -1) {
count++;
max = max.substring(index + min.length());
}else{
break;
}
}
System.out.println(count);
}
}
|
|