admin 管理员组

文章数量: 887021

双色球每注投注号码由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转为ArrayListArrayList<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("你没有中奖,请继续努力");}}

本文标签: 双色球每注投注号码由6个红色球号码和1个蓝色球号码组成红色球从133中随机生成6个不重复的号码蓝色球号码从116中随机生成1个客户通过键盘录入购买的红色球6个(不重复)和蓝色球1个 判断