public class StringTest1 {
public static void main(String args[])
{
String str="nbawernbatyunbaidfnbaghjnba";
String key="nba";
int count=getSunCount(str,key);
System.out.println(count);
}
public static int getSunCount(String str,String key)
{
int count=0;
int index=0;
while((index=str.indexOf(key))!=-1) 正确的应该为 while((index=str.indexOf(key,index))!=-1)
{
index=index+key.length();
count++;
}
return count;
}
}
导致电脑死机了
|
|