当前位置:编程学习 > JAVA >>

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

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[i]) == null ? 0 : (Integer) m.get(args[i])); 
     
            m.put(args[i], (freq == 0 ? 1 : freq + 1)); 
        } 
         
        System.out.println 
            (m.size() + " distinct words detected:"); 
        System.out.println(m); 
    }    




摘自 Yours风之恋
补充:软件开发 , Java ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,