我想做一个程序,要实现的功能是,输入一篇英文,然后统计一下单词的出现频率,我没有一点思路啊,有高手指教一下啊,谢谢了

解决方案 »

  1.   

    给你一个大致的雏形 后面解析单词的思路就自己来了!package kane;import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileReader;
    import java.io.IOException;public class ReadLine { public static void main(String[] args) {
    BufferedReader reader = null;
    try {
    File readFile = new File("D://Projects//Paper.txt");
    reader = new BufferedReader(new FileReader(readFile));
    String temp = null;
    int line = 1;
    while ((temp = reader.readLine()) != null) {
    System.out.println("Line" + line + ":" + temp);
    line++;
    }
    reader.close();
    } catch (Exception e) {
    e.printStackTrace();
    } finally {
    if (reader != null) {
    try {
    reader.close();
    } catch (IOException e1) {
    }
    }
    }
    }
    }
      

  2.   

    前提在上述的路径下有Paper这一文件,程序包名为Kane 这个可以自己修改
      

  3.   

    楼主的意思应该没有那么麻烦··因为他要求·文章是输入的··那可以直接当作字符串来处理··然后subString()查找就行了``
      

  4.   

    public class Tontji {
    public static void main(String[] args) {
    //输出aa出现的次数
    String s=" a aa aa aaa aa a aa aa aaa aa ";
    int sum=0;
    int a=0;
    int c=0;
    while(a!=-1){
    a=s.indexOf(" aa ",c); 
    c=a+3;
    sum++;
    }
    System.out.println("the word \"aaa\" has appead "+(sum-1)+" times");
    }}我也是初学者,楼主的问题,我也不知道怎么解决,这个是我的一个思路,也存在很多问题,我也不知道怎么解决。
    坐等高手
      

  5.   

    (1)正则表达式分词。
    (2)C语言中的strtok()函数或许对你有帮助。
      

  6.   

    嗯,这个就是思路,读取文件用到I/O,,读入每行,是readline()方法,然后正则表达式,以及息加加方法,
      

  7.   

    public static void main(String[] args) { int count=0;
    try {
    BufferedReader br = new BufferedReader(new FileReader("D:\\fan.java"));
    String line = "";
    while((line=br.readLine()) != null) {
    Pattern p = Pattern.compile("fclxyz");
    Matcher m = p.matcher(line);
    while(m.find()) {
    count++;
    }
    }
    } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    System.out.print(count);
    }我去查了一下,这个应该可以,这个程序是查fan.java中fclxyz出现的次数