1. 有一个字符串"woaiheimahahaheimaaiwo"求该字符串中"heima"出现的次数
public static void main(String[] args) {
String str="woaiheimahahaheimaaiwo";
int count =0;
int index=-1;
int len="heima".length();
for (int i = 0; i < str.length(); i++) {
if ((index=str.indexOf("heima"))!=-1) {
str=str.substring(index+len);
count++;
}else {
break;
}
}
System.out.println(count);
}
}
|
|