练习7,大串中统计小串的次数

package com.heima.test;

public class StringTest3 {

    /**练习7,大串中统计小串的次数 * @param args */
    public static void main(String[] args) {
        String max = "asdfgnbxvcnjwqeasdfgxcnxcnnasdfgc,vmkeasdfgkjrier";
        String min = "asdfg";
        int count = 0;
        int index = 0;
        while((index = max.indexOf(min)) != -1){
            count++;
            max = max.substring(index+min.length());
        }
        System.out.println(count);
    }

}

你可能感兴趣的:(练习7,大串中统计小串的次数)