恳请各位高手帮帮忙。
谢谢大家!!

解决方案 »

  1.   

    用split(" ")切割成单词数组,然后排序,再逐个计数
      

  2.   

    首先用split分割,然后用map统计每个字符出现的次数,然后拿出最多的3个
    代码自己想思路就是这样
      

  3.   

    对,用 hash 表,用单词作关键字,单出出现的次数作值当找到一个单词时,到 hash 表中去找关键字,如果找到就让它对应的值加1,否则把这个单词作关键字,1作值加到这个 hash 表中去
      

  4.   

    import java.util.*;public class Lookup{
        public static void main(String[] args){
            String s = "the instruction set of the Java virtual machine distinguishes its operand types using instructions intended to operate on values of specific types";
            String[] word = s.split(" ");
            Map<String,Integer> m = new HashMap<String,Integer>();
            //用word初使化m,m中包含了所有不重复的单词
            for(int j=0;j<word.length;j++){
                m.put(word[j],0);
            }
            
            Set<String> set = m.keySet(); 
            //用word中的每个单词与m中的单词比较,发现相同的就统计一次    
            for(int i=0;i<word.length;i++){
            Iterator<String> it = set.iterator();
             while(it.hasNext()){
                  String k = it.next();
                  if(word[i].equals(k)){
                        int c = m.get(k);                  
                        c++;
                        m.put(word[i],c);
                    }
                }                          
            }
            System.out.println(m);
        }
    }
      

  5.   

    一帮学院派。既然是单词处理,必须要进行一些操作,统一大小写,对于 He's   I'm之类的把缩写去除。 对于全大写的字符认为是缩写特殊处理,对于首尾的符号要进行去除,对于中间的符号要重新段词 。 是一个至少几天的工作量。
      

  6.   

    1. 分词
    根据特定的分词符,如空格和单引号等,将句子分成单词组,用split就可以办到。
    2.遍历split后的数组,使用正则表达式计算每个单词出现的频率。
    正则表达式的.Net代码,Apache Regex类库中有类似的正则表达式代码MatchCollection 类表示非重叠匹配的序列  该集合为只读的,并且没有公共构造函数。MatchCollection 的实例是由 Regex.Matches 属性返回的。使用 Regex 类的 Matches 方法,通过在输入字符串中找到的所有匹配填充 MatchCollection。下面代码示例演示了如何将集合复制到一个字符串数组(保留每一匹配)和一个整数数组(指示每一匹配的位置)中。MatchCollection mc;
    String[] results = new String[20];
    int[] matchposition = new int[20];
    Regex r = new Regex("abc"); //定义一个Regex对象实例
    mc = r.Matches("123abc4abcd");
    for (int i = 0; i < mc.Count; i++) //在输入字符串中找到所有匹配
    {
     results[i] = mc[i].Value; //将匹配的字符串添在字符串数组中
     matchposition[i] = mc[i].Index; //记录匹配字符的位置
    }
      

  7.   

    楼上有用正则的,有用map的,学习了,尤其是用map的上楼,回想起了以前写的代码。
      

  8.   

    哈哈,还要给map排序呀
    按值排序
      

  9.   

    把一串单词转换成LIST集合,然后迭代可以知道每个单词的个数.都知道个数了再想知道那个最大应该不难了吧List list = ............
    Iterator it = list.iterator();
    while(it.hasNext()){
       Object o = it.next();
       System.out.println(o.toString()+" "+Collections.frequency(list,o));
    }
      

  10.   

    怎么和我们实验报告一样啊!思路:
    1. 读取英文文章。(StringBuffer str)
    2. 读到内存当中后,需要对其进行合理截取。考虑文章1M左右地情况,而且对文章标点符号截取考虑(,.!;空格回车)while(iterator.hasNext())
    iterator.next(); //取出单词之后
    HashMap map = new HashMap();
    //map.get(word) == null ? map.put(word,1) : map.put(word, map.get(word) + 1);His name is John. John is 16 years old His.
    StringTokenizer st = StringTokenizer(str, ",.! \n");
    while (st.hasMoreTokens()){
    String word = st.nextToken();
    //word = His
    //map的key是出现地英文单词,value是出现的次数
    if(map.get(word) == null)
    map.put(word, 1);
    else 
    int value = map.get(word);
    map.put(word, value + 1);
    }
    System.out.println(map);
    His=1, name=1,is=2,John=2......map.keySet  set His,name,
    iterator{
    TreeSet<NewStudent> list = TreeSet<NewStudent>(new new Comparator() { @Override
    public int compare(Object o1, Object o2) {
    // TODO Auto-generated method stub
    NewStudent stu1 = (NewStudent)o1;
    NewStudent stu2 = (NewStudent)o2;
    return stu1.compareTo(stu2);  
    }

    });
    NewSutdent ns = new NewSutdent(His, map.get(His));
    set.add(ns);
    }
    //set 前十个集合
    NewStudent() implemets Comparable{
    NewStudent(String word, int times)

    times
    }