class StrigTest3
{
public static void main(String[] args)
{
int count =getCount("afrbcfrtyhgtfrbgfrd","fr");
System.out.println("count="+count);
}
public static int getCount(String str,String sub)
{
int count=0;
int index=0;
while ((index = str.indexOf(sub))!=-1)//对于这个while语句的作用不是很明白,请高手指点
{
str = str.substring(index+sub.length(),str.length());
count++;
}
return count;
}
} |