import java.util.Scanner;//双色球模拟系统
import java.util.Arrays;
import java.util.Random;
public class Test{
public static void main(String[] args) {
int[] userRedBall = new int[6];
int[] sysRedBall = new int[6];
int userBlueBall = 0;
int sysBlueBall = 0;
int redCount=0;
int blueCount = 0;
int[] redBall = new int[33];
Scanner input = new Scanner(System.in);
Random r = new Random();
for(int i=0;i<=redBall.length-1;i++)
{
redBall[i]=i+1;
}
System.out.println("选择机选还是手选 1:机选 2:手选");
boolean flag = true;
while(flag)
{
int isChose = input.nextInt();
switch(isChose)
{
case 1://机选
conputerSelection(redBall,userRedBall);
userBlueBall = r.nextInt(16)+1;
flag=false;
break;
case 2://手选
System.out.println("请选择红球6个不同的号码");
for(int k=0;k<=userRedBall.length-1;k++)
{
userRedBall[k] = input.nextInt();
if(userRedBall[k] < 1||userRedBall[k] > 33)
{
System.out.println("错误,请重新输入");
k--;
}
for(int a=0;a
if(userRedBall[k]==userRedBall[a])
{
System.out.println("重复,请重新输入");
k--;
}
}
}
System.out.println("请选择蓝球的号码");
boolean flag1 = true;
while(flag1)
{
userBlueBall = input.nextInt();
if(userBlueBall < 1||userBlueBall > 16)
{
System.out.println("错误,请重新输入");
}else flag1=false;
}
flag=false;
break;
default:
System.out.println("选择机选还是手选 1:机选 2:手选");
break;
}
}
//系统随机生成号码
conputerSelection(redBall,sysRedBall);
sysBlueBall = r.nextInt(16)+1;
//统计结果
for(int i=0;i<=userRedBall.length-1;i++)
{
for(int j=0;j<=sysRedBall.length-1;j++)
{
if(userRedBall[i]==sysRedBall[j])
redCount++;
}
}
if(sysBlueBall==userBlueBall)
blueCount++;
//公布结果
if(blueCount==0 && redCount<=3)
System.out.println("没中!");
else if(blueCount==1 && redCount<=3)
System.out.println("六等奖");
else if((blueCount==1 && redCount==3)||(blueCount==0 && redCount==4))
System.out.println("五等奖");
else if((blueCount==1 && redCount==4)||(blueCount==0 && redCount==5))
System.out.println("四等奖");
else if(blueCount==1 && redCount==5)
System.out.println("三等奖");
else if(blueCount==0 && redCount==6)
System.out.println("二等奖");
else if(blueCount==1 && redCount==6)
System.out.println("一等奖");
else System.out.println("系统异常");
//公布系统号码
System.out.println("本期红色号码为");
Arrays.sort(sysRedBall);
System.out.println(Arrays.toString(sysRedBall));
System.out.println("本期蓝色号码为");
System.out.println(sysBlueBall);
//你选择的号码
System.out.println("你选择的红色号码为");
Arrays.sort(userRedBall);
System.out.println(Arrays.toString(userRedBall));
System.out.println("你选择的蓝色号码为");
System.out.println(userBlueBall);
}
//生成6个不同的随机数
public static void conputerSelection(int[] redBall,int[] userRedBall)
{
Random r = new Random();
int index = -1;
for(int j=0;j<=userRedBall.length-1;j++)
{
index = r.nextInt(redBall.length-j);
userRedBall[j] = redBall[index];
int temp = redBall[redBall.length-j-1];
redBall[redBall.length-j-1]= redBall[index];
redBall[index]=temp;
}
}
}



