标题:想实现一个功能,将1~12个数字分成四组,分别放入a,b,c,d中必须用Map<Stri ...
取消只看楼主
franksking
Rank: 2
等 级:论坛游民
帖 子:16
专家分:43
注 册:2016-4-25
结帖率:83.33%
已结贴  问题点数:10 回复次数:0 
想实现一个功能,将1~12个数字分成四组,分别放入a,b,c,d中必须用Map<String,ArrayList<String>>这个结
    想实现一个功能,将1~12个数字分成四组,分别放入a,b,c,d中必须用Map<String,ArrayList<String>>这个结构,我想问一下该怎么写呢?如果要是分成六组呢,更多呢?
        public static void main(String[] args)
    {
        String[] array={"a","b","c","d"};
        
        int[] num = new int[12];
        Map<String,ArrayList<String>> map = new HashMap();
        for(int i=0;i<num.length;i++)
        {
            num[i]=i+1;
            //System.out.print(num[i]+" ");
        }
        for(int i=0;i<array.length;i++)
        {
            ArrayList list = new ArrayList();
            for(int j=0;j<num.length;j++)
            {
                if(num[j]<4)
                {
                    list.add(String.valueOf(num[j]));
                    continue;
                }
                else if(num[j]>=4&&num[j]<8)
                {
                    list.add(String.valueOf(num[j]));
                    continue;
                }
                else if(num[j]>=8&&num[j]<10)
                {
                    list.add(String.valueOf(num[j]));
                    continue;
                }
                    
                else
                {
                    list.add(String.valueOf(num[j]));
                    continue;
                }   
                    
                    
                    
            }
            map.put(array[i], list);
            
        }
        
        for(String key:map.keySet())
        {
            System.out.println(key+" "+map.get(key));
        }
        
    }
搜索更多相关主题的帖子: public 
2016-04-27 11:23



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-464179-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.365061 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved