class StringMethodTest
{
public static void main(String[] args)
{
String str="abkkcdekkfghkkijkklmn";
int x = getNum(str,"kkk");
System.out.println("出现次数: "+x);
}
public static int getNum(String str,String s)
{
int count;
for (count=0; getIndex(str,s)>=0; count++)
{
str=str.substring(getIndex(str,s)+s.length());
}
return count;
}
public static int getIndex(String str,String s)
{
int x = str.indexOf(s);
return x;
}
}
这是在毕老师讲解之前自己想办法写出来的,虽然比毕老师的麻烦点,但也还行。
这是第一个自己独立完成的小程序,鼓励一下自己!!!!!:victory::victory::victory: |
|