双色球每注投注号码由6个红色球号码和1个蓝色球号码组成。红色球从1—33中随机生成6个不重复的号码;蓝色球号码从1—16中随机生成1个;客户通过键盘录入购买的红色球6个(不重复)和蓝色球1个, 判断

 public static void main(String[] args) {
        //创建随机数
        Random random = new Random();
        //创建奖池红球号的集合
        HashSet<Integer> redBallNumderJackopt = new HashSet<>();
        //红球循环次数(个数)
        while (redBallNumderJackopt.size() < 6) {
            int redBall = random.nextInt(33) + 1;
            redBallNumderJackopt.add(redBall);
            if (redBall != redBall) {
                redBallNumderJackopt.add(redBall);
            }
        }
        System.out.println("红球是:" + redBallNumderJackopt);
        //创建奖池蓝球号的集合
        HashSet<Integer> blueBallNumderJackpot = new HashSet<>();
        int blueBall = random.nextInt(16) + 1;
        //蓝球
        blueBallNumderJackpot.add(blueBall);
        System.out.println("蓝球是:" + blueBallNumderJackpot);

        //创建键盘录入 调用键盘对象
        Scanner scanner = new Scanner(System.in);
        //购买红球号的奖池
        //HashSet<Integer> redBallNumder = new HashSet<>();
        //TreeSet<Integer> redBallNumder = new TreeSet<>();
        ArrayList<Integer> redBallNumder = new ArrayList<>();
        //红球输入次数(计数器)
        int count = 0;
        //输入红球号码
        while (count <= 5) {
            count++;
            System.out.println("请输入红球号码,第" + " " + count + " " + "球:");
            int redBallNumder1 = scanner.nextInt();
            redBallNumder.add(redBallNumder1);
        }
        //购买红球号码的集合输出
        System.out.println(redBallNumder);
        //购买蓝球号码的集合
        HashSet<Integer> blueBallNumder = new HashSet<>();
        //输入蓝球号码
        System.out.println("请输入蓝球号码:");
        int blueBallNumder1 = scanner.nextInt();
        blueBallNumder.add(blueBallNumder1);
        System.out.println(blueBallNumder);
        //红球奖池集合HashSet转为ArrayList
        ArrayList<Integer> integers = new ArrayList<>(redBallNumderJackopt);
        //HashSet<Object> integers = new HashSet<>(redBallNumder);
        //计数器(红球对的个数)
        int count1 = 0;
        for (int index = 0; index < 6; index++) {
            if (integers.contains(redBallNumder.get(index))) {
                count1++;
            }
        }

        //买中蓝色球, 红色球全部买中, 1等奖100万
        if (blueBallNumder.equals(blueBallNumderJackpot)/*&redBallNumder.equals(redBallNumderJackopt)*/) {
            if (count1 == 6) {
                System.out.println("恭喜你获得了一等奖,奖金100万");
            } else
                //买中蓝色球,红色球买中3-5个, 2等奖50万
                if (count1 >= 3 && count1 <= 5) {
                    System.out.println("恭喜你获得了二等奖,奖金50万");
                } else
                    //买中蓝色球, 红色球买中1个, 3等奖20万
                    if (count1 == 1) {
                        System.out.println("恭喜你获得了三等奖,奖金20万");
                    }else {
                        System.out.println("你没有中奖,请继续努力");
                    }
        } else {
            System.out.println("你没有中奖,请继续努力");
        }
    }

  • 3
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

官柏

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值