双色球系统

1.投注号码六个红色号码和一个蓝色号码组成,红色号码从1-33中选择;蓝色号码从1-16号选择。

package com.itheima.demo1;
import java.util.Random;
import java.util.Scanner;
public class method {
    public static void main(String[] args) {
        int a[]=new int[7];
        int user[]=new int[7];
        Random r=new Random();
        //机选出来的中将号码
        for (int i = 0;i <6; ) {
            int num=r.nextInt(33)+1;
            if(isright(a,num)){
                a[i]=num;
                i++;
            }
        }
        a[6]=r.nextInt(16)+1;
        for (int i = 0; i < a.length; i++) {
            System.out.print(" "+a[i]);
        }
        //用户自己输入的彩票号码
        for (int i = 0; i <7 ; i++) {
            Scanner sc=new Scanner(System.in);
            user[i]=sc.nextInt();
        }
        money(a,user);
    }
    public static void money(int[]a,int[]b) {
        int red=0,blue=0;
        for (int i = 0; i < a.length-1; i++) {
            for (int j = 0; j <b.length-1; j++) {
                if(a[i]==b[j]) {red++;break;}
            }
        }
        System.out.println(red);
        if(a[6]==b[6]) blue++;
        if(red==6&&blue==1){
            System.out.println("感谢您中了一等奖1000万");
        }
        else if(red==6&&blue==0){
            System.out.println("感谢您中了二等奖500万");
        }
        else if(red==5&&blue==1){
            System.out.println("感谢您中了三等奖3000元");
        }
        else if(red==5&&blue==0||red==4&&blue==1){
            System.out.println("感谢您中了四等奖200元");
        }
        else if(red==4&&blue==0||red==3&&blue==1){
            System.out.println("感谢您中了五等奖10元");
        }
        else if(red==2&&blue==0||red==1&&blue==1||red==0&&blue==1){
            System.out.println("感谢您中了六等奖5元");
        }
        else{
            System.out.println("没中奖");
        }

    }

    public static boolean isright(int[]a,int num) {
        for (int i = 0; i < a.length; i++) {
            if(a[i]==num){
                return false;
            }
        }
        return true;
    }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值