Java实现双色球

public static void main(String[] args) {
		
		int[] winnums = new int[6];//系统随机生成的6位中奖号码球
		int[] nums = new int[6];//用户红色号码球用数组nums[]存储
		int userBlue;//用户蓝色号码球用变量blue存储
		int winBlue;//系统生成的蓝色号码球
		//随机生成1-33数字的6个红球
		for (int i = 0; i < winnums.length; i++) {
			winnums[i] = (int)(Math.random()*(33-1)+1);
		}
		
		//这一段代码用于展示系统生成的随机数,想看可以放开
		/*System.out.print("(红色中奖号码):");
		for (int i = 0; i < winnums.length; i++) {
			System.out.print(winnums[i]+" ");
		}System.out.println();*/
	
		//随机生成1个蓝球
		winBlue = (int)(Math.random()*(16-1)+1);
		System.out.println("(蓝色中奖号码):"+winBlue);
		Scanner input = new  Scanner(System.in);
		//记录用户输入的红色球
		System.out.println("请输入6个红色号码球(1-33):");
		for (int i = 0; i < nums.length; i++) {
			nums[i] = input.nextInt();
		}
		//记录用户输入的蓝色球
		System.out.println("请输入1个蓝色号码球(1-16):");
		userBlue = input.nextInt();
		int countBlue =0;
		//比较系统和用户的蓝色球是否相等
		if(userBlue==winBlue)
		{
			countBlue=1;
			System.out.println("你蓝色球中了!");
		}else {
			System.out.println("你蓝色球没中");
		}
		//比较系统和用户的红色球是否相等
		int countRed = 0;
		for (int i = 0; i < nums.length; i++) {
			for (int j = 0; j < nums.length; j++) {
				if(nums[j]==winnums[i]) {
					countRed++;
					break;
				}
			}
			
		}
		System.out.println("你红色球中奖个数为:"+countRed);
		if(countBlue==1&&countRed==0) {
			System.out.println("恭喜你!中了六等奖!");
		}
		else if(countRed==1&&countBlue==1) {
			System.out.println("恭喜你!中了六等奖!");
		}
		else if(countRed==2&&countBlue==1) {
			System.out.println("恭喜你!中了六等奖!");
		}
		else if(countRed==3&&countBlue==1) {
			System.out.println("恭喜你!中了五等奖!");
		}
		else if(countRed==4&&countBlue==0) {
			System.out.println("恭喜你!中了五等奖!");
		}
		else if(countRed==4&&countBlue==1) {
			System.out.println("恭喜你!中了四等奖!");
		}
		else if(countRed==5&&countBlue==0) {
			System.out.println("恭喜你!中了四等奖!");
		}
		else if(countRed==5&&countBlue==1) {
			System.out.println("恭喜你!中了三等奖!");
		}
		else if(countRed==6&&countBlue==0) {
			System.out.println("恭喜你!中了二等奖!");
		}
		else if(countRed==6&&countBlue==1) {
			System.out.println("恭喜你!中了一等奖!");
		}
		else {
			System.out.println("很遗憾,你没有中奖!");
		}
	}

在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值