JAVA用StringTokenizer方法计算字符串中的某词的个数问题

本人是初学JAVA 求高人指点

要求
设方法tongji(String s)判断参数s,这个字符串中包含the单词的个数。不区分大小写。例如,有下面的字符串
“The great wall is a the most wonderful building”
写出这个方法,用StringTokenizer类来做

希望能写出编码 谢谢了

import java.util.StringTokenizer;

public class Test {
public static int tongji(String input) {
int count = 0;
StringTokenizer tokenizer = new StringTokenizer(input);
while (tokenizer.hasMoreElements()) {
String element = (String) tokenizer.nextElement();
if ("the".equalsIgnoreCase(element))
count++;
}
return count;
}

public static void main(String[] args) {
System.out.println(tongji("The great wall is a the most wonderful building"));
}
}
温馨提示:答案为网友推荐,仅供参考
相似回答