zoukankan      html  css  js  c++  java
  • 实验2

    import java.util.HashMap;

    import java.util.Iterator;

    import java.util.Map;

    import java.util.Set;

    public class demo{

    private Map<String, Integer> wordsMap;

    public demo(String strWords){

        wordsMap=this.getArray(strWords);

    }

     

    public Map<String,Integer>getArray(String strWords){

        String[] words_Array =strWords.split("  ");

        Map<String,Integer>words_Map=new HashMap<String,Integer>();

       

        int arrLength=words_Array.length;

        for(int i=0;i<arrLength;i++){

            if(!words_Map.containsKey(words_Array[i])){

                words_Map.put(words_Array[i],1);

            }/*else{

                int currentNum=words_Map.get(words_Array[i])+1;

                words_Map.remove(words_Array[i]);

                words_Map.put(words_Array[i],currentNum);

            }*/

        }

        return words_Map;

    }

     

     

    public void OutputResult(){

        Set<String> s=wordsMap.keySet();

        Iterator i= s.iterator();

        while(i.hasNext()){

            Object o=i.next();

            System.out.println(o+"出现了次数为"+wordsMap.get(o));

        }

    }

    public static void main(String[] args){

        demo d=new demo("hello word word");

        d.OutputResult();

    }

  • 相关阅读:
    共享开发者账号
    IOS开发之关键字synchronized
    svn in xcode5
    Xcode5真机调试
    iOS autolayout
    ios正则表达式
    UITextView与UITextfield的区别
    MyBatis笔记(一)
    JAVA命名规则
    ORACLE SQL DEVELOPER配置
  • 原文地址:https://www.cnblogs.com/a13857a/p/5343239.html
Copyright © 2011-2022 走看看