侧边栏壁纸
  • 累计撰写 59 篇文章
  • 累计创建 0 个标签
  • 累计收到 17 条评论

java模拟随机彩票中头奖,打印彩票号码

小熊博客
2021-05-10 / 0 评论 / 1 点赞 / 1,238 阅读 / 3,339 字
温馨提示:
本文最后更新于 2021-08-26,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

最近在做一夜暴富的美梦,每天按照自己随机出的头奖号码购买,花几分钟写了个模拟程序。图个心理安慰

代码


        LinkedHashMap<String, Object> winning = new LinkedHashMap();
        Random random = new Random();
        int randomBlue = random.nextInt(15)+1;
        winning.put("Blue", randomBlue);
        List<Integer> redList = new ArrayList<Integer>();
        for (int i = 0; i < 6; i++) {
            while (true) {
                int randomRed = random.nextInt(32) + 1;
                if (!redList.contains(randomRed)) {
                    redList.add(randomRed);
                    break;
                }
            }
        }
        winning.put("red", redList);
        System.out.println("彩票开奖号码 - 红球:" + redList + "蓝球:" + randomBlue);
        int outMoney = 0;
        int theMoney = 0;
        int one=0,two=0,three=0,four=0,five=0,six=0;
        while (true) {
            List<Integer> redOutList = new ArrayList<>();
            outMoney = outMoney + 2;
            int redNum = 0;
            boolean blue = false;
            for (int i = 0; i < 6; i++) {
                while (true){
                    int randomRed = random.nextInt(32) + 1;
                    if (!redOutList.contains(randomRed)){
                        redOutList.add(randomRed);
                        if (redList.contains(randomRed)) {
                            redNum++;
                        }
                        break;
                    }
                }
            }
            int buyBlue = random.nextInt(16);
            if (Integer.parseInt(winning.get("Blue").toString()) == buyBlue) {
                blue = true;
            }
            if (redNum == 6 && blue) {
                theMoney = theMoney + 5000000;
                System.out.println("喜提一等奖中奖号码 - 红球" + redOutList + "蓝球" + buyBlue);
                System.out.println("彩票开奖号码 - 红球:" + redList + "蓝球:" + randomBlue);
                System.out.println("二等奖中奖个数:"+two);
                System.out.println("三等奖中奖个数:"+three);
                System.out.println("四等奖中奖个数:"+four);
                System.out.println("五等奖中奖个数:"+five);
                System.out.println("六等奖中奖个数:"+six);
                System.out.println("总花费金额" + outMoney);
                System.out.println("总收获金额" + theMoney);
                break;
            } else if (redNum == 6) {
                two++;
                theMoney = theMoney + 100000;
                continue;
            } else if (redNum == 5 && blue) {
                three++;
                System.out.println("三千块 - 红球" + redOutList + "蓝球" + buyBlue);
                theMoney = theMoney + 3000;
                continue;
            } else if (redNum == 5 || blue && redNum == 4) {
                four++;
                System.out.println("两百块 - 红球" + redOutList + "蓝球" + buyBlue);
                theMoney = theMoney + 200;
                continue;
            } else if (redNum == 4 || blue && redNum == 3) {
                five++;
                System.out.println("十块 - 红球" + redOutList + "蓝球" + buyBlue);
                theMoney = theMoney + 10;
                continue;
            } else if (blue) {
                six++;
                System.out.println("五块 - 红球" + redOutList + "蓝球" + buyBlue);
                theMoney = theMoney + 5;
                continue;
            }
        }

运行效果

image.png

1

评论区