使用java编写程序,要求输入一段话,统计其中某个词语出现的次数.我是初学者 易懂点的

发布时间:2021-02-22 16:46:34

使用java编写程序,要求输入一段话,统计其中某个词语出现的次数.我是初学者 易懂点的

网友回答

import java.io.*;
public class Test1 {
public static void main(String[] args) throws IOException{
String source = null;
String key = ;
//从键盘接受输入的一段话
BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
source = reader.readLine();
key = as; //待统计出现频度的词语
int num = GetFrequency(source, key);
System.out.println(key + 在这段话中出现的频度为 + num);
}public static int GetFrequency(String source,String key){
int i, j, count = 0;
int len1 = source.length(); //这段话的长度
int len2 = key.length(); //待统计词语的长度
for(i=0; i
以上问题属网友观点,不代表本站立场,仅供参考!