栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

84452抽签Java版

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

84452抽签Java版

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

public class Test {


    public static void main(String[] args) {
        Map> map = new HashMap();

        Map A = new HashMap<>();
        Map B = new HashMap<>();
        Map C = new HashMap<>();
        Map D = new HashMap<>();

        A.put(0,"paris");
        A.put(1,"crystal");
        B.put(0,"milan");
        B.put(1,"porto");
        C.put(0,"forest");
        C.put(1,"chelsea");
        D.put(0,"mancity");
        D.put(1,"barcelona");

        map.put(0,A);
        map.put(1,B);
        map.put(2,C);
        map.put(3,D);

        Random random = new Random();
//        System.out.println(random.nextInt(4));
//        System.out.println(random.nextInt(4));
//        System.out.println(random.nextInt(4));
//        System.out.println(random.nextInt(4));
//        System.out.println(random.nextInt(4));

        int i = 100;
        int j = 100;
        Map m = null;
        int count = 0;

        int group = 4;   //记录组信息

        

        //js可以用下面这个判断key是否存在
        //ary.hasOwnProperty(key); 或 obj.hasOwnProperty(key);
        while (count < 8) {
            i = random.nextInt(1000) % 4;  // 先抽取一个小组
            if(i == group) {  //如果同组重新抽
                continue;
            }
            if(map.containsKey(i)){  //判断一下是否已经被抽取,防止异常
                m = map.get(i);
                if (count % 2 == 0 || count == 0){  // 判断是否需要抽球队,这个也可以不用,直接按照先抽第一再抽第二就行了
                    j = random.nextInt(1000) % 2;
                }else {
                    if (j == 1){
                        j--;
                    }else {
                        j++;
                    }
                }
                if(m.containsKey(j)){
                    count++;
                    System.out.println("第" + count + "个队伍是:" + m.get(j));
                    if (count % 2 != 0) {
                        group = i;
                    }else {
                        group = 4;
                    }
                    map.get(i).remove(j);  //抽完排除掉
                }
            }
        }

    }
}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/726632.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号