请输入大字符串:woaiheima,heimabutongyubaima,wulunheimahaishibaima,zhaodaogongzuojiushihaoma
请输入小字符串:heima
请计算出小字符串在大字符串中出现的次数
public static void main(String[] args) {
String bigStr = "woaiheima,heimabutongyubaima,wulunheimahaishibaima,zhaodaogongzuojiushihaoma";
String str = "heima";
int index = 0;
int count = 0;
while ((index = bigStr.indexOf(str)) != -1) {
index += str.length();
count++;
bigStr = bigStr.substring(index);
}
System.out.println(count);
} |
|