import java.util.Random;
import java.util.Scanner;
public class choujiang {
public static void main(String[] args) {
//方法1:用户输入
int [] usernumbers = new int[7];
usernumber(usernumbers);
//方法2:中奖号码确定 随机数
int [] lucknumbers = new int[7];
lucknumber(lucknumbers);
//方法3:判断中奖个数
checknumber(usernumbers,lucknumbers);
}
public static void usernumber(int [] usernumbers)
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入前6个红球的数字");
for (int i = 0; i < usernumbers.length - 1; i++)
{//遍历前6位
while (true)
{
System.out.println("请输入第" + (i + 1) + "个红球的数字(1~33之间!):");
int number = sc.nextInt();
if (number > 33 || number < 1)
{
System.out.println("请重新输入!");
}
else
{
if (check(number, usernumbers))//判断号码是否重复输入
{
System.out.println("请不要重复输入!");
}
else
{
usernumbers[i] = number;//号码没有重复输入,记录该号码
break;//并且跳出while循环
}
}
}
}
while (true)
{//与上方判断红球数字同理
System.out.println("请输入最后一个蓝球的数字(1~16之间!)");
int number = sc.nextInt();
if (number > 16 || number < 1)
{
System.out.println("请重新输入!");
}
else
{
usernumbers[usernumbers.length - 1] = number;
break;
}
}
}
public static void lucknumber(int[]lucknumbers)
{//生成中奖号码
Random r = new Random();//随机数
for (int i = 0; i < lucknumbers.length - 1; i++)
{
while (true)
{
int number = r.nextInt(33) + 1;//生成在1~33之间的号码
if (!check(number,lucknumbers))//且号码不重复
{
lucknumbers[i] = number;
break;
}
}
}
int number1 = r.nextInt(16) + 1;
System.out.print("中奖号码为:");
for (int i = 0; i < lucknumbers.length; i++)
{
System.out.print(lucknumbers[i] + " ");//打印中奖号码
}
}
public static void checknumber(int[]usernumbers, int[]lucknumbers)
{//确定用户红色球中奖个数以及蓝色球中奖个数
int count1 = 0;
for (int i = 0; i < usernumbers.length - 1; i++)
{
for (int j = 0; j < usernumbers.length - 1; j++)
{
if (usernumbers[i] == lucknumbers[j])
count1++;
}
}
System.out.println("您中的红色球数量为" + count1);
int count2 = 0;
if (lucknumbers[lucknumbers.length - 1] == usernumbers[usernumbers.length -1])
{
count2++;
}
System.out.println("您中的蓝色球数量为:" + count2);
//输出相对应的奖励,自行定义!
if (count1 == 6 && count2 == 1)
{
System.out.println("恭喜你!中了1000万!可以躺平了!");
}
else if (count1 == 6 && count2 ==0)
{
System.out.println("恭喜你!中了500万!");
}
else if (count1 == 5 && count2 ==1)
{
System.out.println("恭喜你!中了3000元!");
}
else if (count1 == 5&& count2 ==0)
{
System.out.println("恭喜你!中了2000元!");
}
else if (count1 == 4&& count2 ==1)
{
System.out.println("恭喜你!中了2000元!");
}
else
{
System.out.println("感谢您为福利事业做出的贡献!");
}
}
public static boolean check(int number, int[] numbers)
{//判断输入/生成随机数是否重复
for (int i = 0; i < numbers.length-1; i++)
{
if (number == numbers[i])
{
return true;//如果相同返回true,while(true)会继续执行,让用户/系统重新生成
}
}
return false;
}
}