統計サブストリングが別の文字に表示される回数

2120 ワード

package cc;

////
public class StringTest1 {
    public static void main(String[] args) {
        StringDemo1 demo1 = new StringDemo1();
        System.out.println(" " + demo1.count("abcabcccabc", "abc"));
    }
}

class StringDemo1 {
    public int count(String string, String subString) {
        int count = 0;
        while (string.indexOf(subString) != -1) {//  
            count++;
            int local = string.indexOf(subString);
            string = string.substring(local + 1);//  local+1
        }
        return count;
    }
}

回転:http://blog.csdn.net/lfdfhl/article/details/8195110