java利用Math累的random方法生成1到35区间的随机数,一组7个生成5组,分别存在5个Map类型的对象中

如题所述

public static void main(String[] args) {
        Map<Integer, Map<Integer, Integer>> lotteryTicketMap = new HashMap<Integer, Map<Integer,Integer>>();
        Random r = new Random();
        for(int i = 0 ; i < 5;i++){
            Map<Integer, Integer> map = new HashMap<Integer, Integer>();
            for(int j = 0 ; j < 7 ; ){
                int num = r.nextInt(35)+1;
                if(map.get(j)==null){
                    map.put(j, num);
                    j++;
                }
            }
            lotteryTicketMap.put(i, map);
        }
        System.out.println(lotteryTicketMap);
    }

温馨提示:答案为网友推荐,仅供参考
相似回答