蕉园诗社
幼苗
共回答了11个问题采纳率:100% 举报
等我,就写出来
import java.io.*;
import java.util.HashMap;
import java.util.Map.Entry;
public class Test {
x05/**
x05 * @param args
x05 */
x05public static void main(String[] args) {
x05x05// TODO Auto-generated method stub
x05x05try {
x05x05x05BufferedReader br = new BufferedReader(new FileReader("C:\text.txt"));//我就不写有界面的了,这个参数就是你英文句子文件所在位置
x05x05x05String sentence = null;
x05x05x05HashMap map = new HashMap();
x05x05x05while((sentence = br.readLine())!=null){
x05x05x05x05sentence = sentence.replaceAll("[\pP'$']","");
x05x05x05x05String[] words = sentence.split(" ");
x05x05x05x05for(String word:words){
x05x05x05x05x05if(map.get(word)==null)
x05x05x05x05x05map.put(word,1);
x05x05x05x05x05else map.put(word,map.get(word)+1);
x05x05x05x05}
x05x05x05}
x05x05x05java.util.Iterator iter = map.entrySet().iterator();
x05x05x05while(iter.hasNext()){
x05x05x05x05Entry entry = (Entry) iter.next();
x05x05x05x05System.out.println(entry.getKey()+" "+entry.getValue());
x05x05x05}
x05x05} catch (FileNotFoundException e) {
x05x05x05// TODO Auto-generated catch block
x05x05x05e.printStackTrace();
x05x05} catch (IOException e) {
x05x05x05// TODO Auto-generated catch block
x05x05x05e.printStackTrace();
x05x05}
}
}
1年前
6