第1个回答 2009-10-14
public class test11 {
String s = "abclfdlsjfabc0";
public void aa(){
int count=0;
while(s.indexOf("abc")>=0)
{
count++;
s=s.replaceFirst("abc",""); //将统计过的abc替换为空 然后继续循环
}
System.out.println(count);
}
public static void main(String args[]){
test11 te = new test11();
te.aa();
}
}
楼上的错了,你可以看这个。可以直接使用,帮你测好了
第2个回答 2009-10-14
int count=0;
String s="abcdabcbabceabcfabcg";
while(s.indexof("abc")>0)
{
count++;
s=s.replace("abc",""); //将统计过的abc替换为空 然后继续循环
}
补充wj154005000一点:while(s.indexof("abc")>0)应为while(s.indexof("abc")>=0)
第3个回答 2009-10-14
直接用for循环,循环体外定义一个数字变量,初始值为零。然后一个一个去比较,只要是出现你的规则字符,那么就让那个数字变量加1. 循环完毕后,打出这个数字变量就行了
第4个回答 2009-10-14
int count=0;
String s="abcdabcbabceabcfabcg";
while(s.indexof("abc")>0)
{
count++;
s=s.replace("abc",""); //将统计过的abc替换为空 然后继续循环
}