模拟双色球系统-判断中奖情况

 

package Java_project_1;

import java.util.Random;
import java.util.Scanner;

public class Java_project_1 {
    public static void main(String[] args) {
        int[] usrNumber=userInputNumber();
        printArray(usrNumber);

        System.out.println("中奖号码为:");
        int[] luckNumber=createLuckNumber();
        printArray(luckNumber);

        judge(luckNumber,usrNumber);
    }
    public static void judge(int[] luckNumbers,int[] userNumbers){
        int redHitNumbers=0;
        int blueHitNumbers=0;

        for (int i=0;i<userNumbers.length-1;++i){
            for (int j=0;j<luckNumbers.length-1;++j){
                if(userNumbers[i]==luckNumbers[j]){
                    ++redHitNumbers;
                    break;
                }
            }
        }
        blueHitNumbers=luckNumbers[6]==userNumbers[6]?1:0;

        System.out.println("你命中了" + redHitNumbers + "红球");
        System.out.println("你" + (blueHitNumbers == 1 ? "是" : "否") + "命中蓝球");

        if (redHitNumbers == 6 && blueHitNumbers == 1) {
            System.out.println("恭喜您!中了一等奖~ 奖金1000万已入账~~");

        } else if (redHitNumbers == 6 && blueHitNumbers == 0) {
            System.out.println("恭喜您!中了二等奖~ 奖金500万已入账~~");

        } else if (redHitNumbers == 5 && blueHitNumbers == 1) {
            System.out.println("恭喜您!中了三等奖~ 奖金3000元已入账~~");

        } else if ( (redHitNumbers == 5 && blueHitNumbers == 0) || (redHitNumbers == 4 && blueHitNumbers == 1) ) {
            System.out.println("恭喜您!中了四等奖~ 奖金200元已入账~~");

        } else if ( (redHitNumbers == 4 && blueHitNumbers == 0) || (redHitNumbers == 3 && blueHitNumbers == 1)) {
            System.out.println("恭喜您!中了五等奖~ 奖金10元已入账~~");

        } else if (redHitNumbers <3 && blueHitNumbers == 1) {
            System.out.println("恭喜您!中了六等奖~ 奖金5元已入账~~");

        }else {
            System.out.println("感谢您为福利事业作出的伟大贡献!!");
        }
    }
    public static void printArray(int[] arr){
        for (int i=0;i< arr.length;++i){
            System.out.print(arr[i] + "\t");
        }
        System.out.println();
    }
    public static int[] userInputNumber(){
        int[] numbers=new int[7];
        Scanner sc=new Scanner(System.in);
        for(int i=0;i< numbers.length-1;++i){
            System.out.println("请用户输入第" + i + "个红球号码(0-33不重复):");
            numbers[i]=sc.nextInt();
        }
        System.out.println("请输入蓝球号码:");
        numbers[numbers.length-1]= sc.nextInt();
        return numbers;
    }
    public static int[] createLuckNumber(){
        int[] numbers=new int[7];
        Random r=new Random();
        for(int i=0;i< numbers.length-1;++i){
            while (true){
                int data=r.nextInt(33)+1;
                boolean flag=true;
                for (int j=0;j<i;j++){
                    if(numbers[j]==data){
                        flag=false;
                        break;
                    }
                }
                if (flag) {
                    numbers[i]=data;
                    break;
                }
            }
        }
        numbers[numbers.length-1]= r.nextInt(16)+1;
        return numbers;
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

亖嘁

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

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

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

打赏作者

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

抵扣说明:

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

余额充值