class StringDemo2//这个类用来处理字符串的子串出现的次数的问题
{
public int getCount(String s1,String s2)
{
int count =0;
int start =0,end=s1.length();
if(s1.contains(s2))
{
while(start<=end&&s1.contains(s2))
{
start=s1.indexOf(s2)+s2.length();
s1=s1.substring(start,end);
end=s1.length();
count++;
}
}
else
{
System.out.println("子串不存在");
}
return count;
}
}
|
|