package com.day06.www;
import java.util.Random;
import java.util.Scanner;
/*双色球:规则如下:投注号码由六个红球号码和一个蓝色号码组成。红球号码从1-33选择
* 蓝球号码从1-16选择
* 中奖条件和奖金表: 红色 蓝色 金额
* 6 1 1000万
* 6 0 500万
* 5 1 3000元
* 5 0 200元
* 4 1 200元
* 4 0 10元
* 3 1 10元
* 2 1 5元
* 1 1 5元
* 0 1 5元
* */
public class Demo07双色球 {
public static void main(String[] args) {
int[] luckNumber = creatLuckNumber();
int[] userNumber = guessNumber();
judge(luckNumber, userNumber);
}
//------------------------------------------------------------------------------------
//定义一串随机生成中奖号码的数字存入数组
public static int[] creatLuckNumber() {
int[] numbers = new int[7];
Random sc = new Random();
//六个红球,所以生成length-1个红球
for (int i = 0; i < numbers.length - 1; i++) {
while (true) {
int data = sc.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] = sc.nextInt(16) + 1;
//输出随机生成的中奖号码;
System.out.println("生成的随机中奖号码是:");
for (int i = 0; i < numbers.length; i++) {
System.out.print(numbers[i] + "\t");
}
System.out.print("\n");//换行方便观看输出结果;
return numbers;
}
//------------------------------------------------------------------------------------
//定义一个数组存放你要猜测的号码
public static int[] guessNumber() {
Scanner sc = new Scanner(System.in);
int[] Numbers = new int[7];
//将六个红球号码录入数组
for (int i = 0; i < Numbers.length - 1; i++) {
System.out.println("请您输入第" + (i + 1) + "个红球号码:(1-33,要求不重复)");
int data = sc.nextInt();
Numbers[i] = data;
}
System.out.println("请您输入蓝球号码:(1-16)");
Numbers[Numbers.length - 1] = sc.nextInt();
return Numbers;
}
//------------------------------------------------------------------------------------
//定义方法判断中奖情况
public static void judge(int[] arr1, int[] arr2) {
//定义两个变量来记录红球和蓝球猜中的数量
int red = 0;
int blue = 0;
for (int i = 0; i < arr2.length - 1; i++)
for (int j = 0; j < arr1.length - 1; j++) {
if (arr2[j] == arr1[i]) {
red++;
break;
}
}
//判断蓝球是否猜中
if (arr1[arr1.length - 1] == arr2[arr2.length - 1])
blue++;
//开始判断中奖情况
if (blue == 1 && red < 3) {
System.out.println("恭喜您,中了5元小奖!");
} else if (blue == 1 && red == 3
|| blue == 0 && red == 4) {
System.out.println("恭喜您,中了10元小奖!");
} else if (blue == 1 && red == 4
|| blue == 0 && red == 5) {
System.out.println("恭喜您,中了200元!");
} else if (blue == 1 && red == 5) {
System.out.println("恭喜您,中了3000元大奖!");
} else if (blue == 0 && red == 6) {
System.out.println("恭喜您,中了500万超级大奖!");
} else if (blue == 1 && red == 6) {
System.out.println("恭喜您,中了1000万巨奖!可以开始享受人生,诗和远方!!");
} else {
System.out.println("感谢您为福利事业做出的突出贡献!!");
}
}
}
模拟双色球中奖 #java
于 2022-06-24 22:39:32 首次发布