goback add

java例程练习(用HashMap记录控制台输入)

2942 点击·0 回帖
灯火互联
楼主

import java.util.*;
public class TestArgswords {
    
    public static void main(String[] args) {
        Map m = new HashMap();
        
        for(int i = 0; i < args.length; i++) {
            
            int freq = ((Integer) m.get(args) == null ? 0 : (Integer) m.get(args));
    
            m.put(args, (freq == 0 ? 1 : freq + 1));
        }
        
        System.out.println
            (m.size() + " distinct words detected:");
        System.out.println(m);
    }    
}


喜欢0 评分0