基于bf算法统计文本中某个单词出现的频率

public class BruteForce2 {
	
	public static int count(String s1, String s2) {
		int count = 0;
		char[] s1s = s1.toCharArray();// t  a  n  l  e  i
		char[] s2s = s2.toCharArray();// a  n
		int begin = 0;
		int i = 0;//
		for(i = 0; i < s1s.length; i++) {
			if(s1s[i] == s2s[begin]) {
				begin++;
				if(begin == s2s.length) {
					count++;
					break;
				} 
			} else {
				continue;
			}
		}
		if(i != s1.length()) {
			count+= count(s1.substring(i + 1, s1.length()), s2);
		}
		return count;
	}
	
	public static void main(String[] args) {
		System.out.println(count("tan3anan", "an"));
	}
}

你可能感兴趣的:(基于bf算法统计文本中某个单词出现的频率)