import java.util.Random;
import java.util.Scanner;
public class Test12 {
public static void main(String[] args) {
//双色球
//1.生成中奖号码
int[] arr = creatNumber();
System.out.println("*************************");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
System.out.println();
System.out.println("*************************");
//2.用户输入中奖号码
int[] userInputNumber = userInputNumber();
//3.统计中奖号码
int redCount = 0;
int blueCount = 0;
for (int i = 0; i < userInputNumber.length - 1; i++) {
for (int j = 0; j < arr.length - 1; j++) {
if (userInputNumber[i] == arr[j]) {
redCount++;
break;
}
}
}
if (userInputNumber[userInputNumber.length - 1] == arr[arr.length - 1]) {
blueCount++;
}
System.out.println(redCount);
System.out.println(blueCount);
//4.判断中几等奖
if (redCount==6&&blueCount==1){
System.out.println("恭喜你,中了1000万");
}else if (redCount==6&&blueCount==0){
System.out.println("恭喜你,中了500万");
}else if (redCount==5&&blueCount==1){
System.out.println("恭喜你,中了3000元");
}else if ((redCount==5&&blueCount==0)||(redCount==4&&blueCount==1)){
System.out.println("恭喜你,中了200元");
}else if ((redCount==4&&blueCount==0)||(redCount==3&&blueCount==1)){
System.out.println("恭喜你,中了10元");
}else if ((redCount==2&&blueCount==1)||(redCount==1&&blueCount==1)||(redCount==0&&blueCount==1)){
System.out.println("恭喜你,中了5元");
}else {
System.out.println("感谢参与");
}
}
//用户输入中奖号码
public static int[] userInputNumber() {
int[] arr = new int[7];
Scanner sc = new Scanner(System.in);
//输入红球号码
for (int i = 0; i < 6; ) {
System.out.println("请输入第" + (i + 1) + "个红球号码");
int redNumber = sc.nextInt();
if (redNumber >= 1 && redNumber <= 33) {
boolean flag = contain(arr, redNumber);
if (!flag) {
arr[i] = redNumber;
i++;
} else {
System.out.println("输入号码已存在");
}
} else {
System.out.println("输入号码超出范围");
}
}
//输入蓝球号码
while (true) {
System.out.println("请输入蓝球号码");
int blueNumber = sc.nextInt();
if (blueNumber >= 1 && blueNumber <= 16) {
arr[arr.length - 1] = blueNumber;
break;
} else {
System.out.println("输入蓝球号码超出范围");
}
}
return arr;
}
//创建中奖号码
public static int[] creatNumber() {
//定义数组存储中奖号码
int[] arr = new int[7];
Random r = new Random();
//生成红球中奖号码
for (int i = 0; i < 6; ) {
int redNumber = r.nextInt(33) + 1;
boolean flag = contain(arr, redNumber);
if (!flag) {
arr[i] = redNumber;
i++;
}
}
//生成篮球中奖号码
int blueNumber = r.nextInt(16) + 1;
arr[arr.length - 1] = blueNumber;
return arr;
}
//判断是否重复
public static boolean contain(int[] arr, int numner) {
for (int i = 0; i < arr.length; i++) {
if (arr[i] == numner) {
return true;
}
}
return false;
}
}