Java方法练习-双色球彩票系统

投注号码由6个红色球号码和1个蓝色球号码组成。
红色球号码从1-33中选择;蓝色球号码从1-16中选择。
一等奖6+1   1000w

二等奖6+0  500w

三等奖 5+1 / 5+0 3000

四等奖4+1 /  4+0 200

五等奖3+1 / 2+1

六等奖1+1 / 1+0  5

package com.lf.Demo.Day4;
import java.util.Scanner;


public class TestPubliCunionLotto {
    public static void main(String[] args) {

        int[] arr2 = BuyNum();

        int[] arr1 = WinNum(7);
        System.out.print("[");
        for(int i=0;i<7;i++){
            if(i<6){
                System.out.print(arr1[i]);
                System.out.print(",");
            }else{
                System.out.print(arr1[i]);
            }
        }
        System.out.println("]");
        

        EstimateArr(arr1,arr2);
    }

    public static int[] WinNum(int number){
        int[] WinNumArr = new int[number];
        for(int i = 0;i<number-1;i++){
            int num1 = (int)(Math.random()*33+1);
            WinNumArr[i] = num1;
        }
        int num2 = (int)(Math.random()*16+1);
        WinNumArr[number-1] = num2;
        return WinNumArr;
    }

    public static int[] BuyNum(){
        int[] BuyNumArr = new int[7];
        for(int i = 1;i<8;i++){
            Scanner sc = new Scanner(System.in);
            System.out.print("请输入要买入的第"+i+"个数字:");
            int num1 = sc.nextInt();
            BuyNumArr[i-1] = num1;
        }
        return BuyNumArr;
    }


    public static void EstimateArr(int[] arr1,int[] arr2){
        int i1 = 0;
        int count1 = 0;
        int count2 = 0;
        while(i1 < 6){
            if(arr1[i1] == arr2[i1]){
                count1++;
            }
            i1++;
        }
        if (arr1[6]==arr2[6]){
            count2 = 1;
        }

        if(count1 == 6 && count2==1){
            System.out.println("恭喜中1000w游戏币");
        } else if (count1 == 6 && count2==0) {
            System.out.println("恭喜中500w游戏币");
        } else if ((count1 == 5 && count2==1)||(count1 == 5 && count2==0)) {
            System.out.println("恭喜中3000游戏币");
        }else if ((count1 == 4 && count2==1)||(count1 == 4 && count2==0)) {
            System.out.println("恭喜中200游戏币");
        }else if ((count1 == 3 && count2==1)||(count1 == 2 && count2==1)) {
            System.out.println("恭喜中50游戏币");
        }else if ((count1 == 1 && count2==1)||(count1 == 1 && count2==0)) {
            System.out.println("恭喜中5游戏币");
        }else {
            System.out.println("很遗憾未中奖");
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值