import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;
public class double_color_ball{
public static void main(String[] args){
//定义相关变量
int[] RedBall = new int[33];
int[] UserSelectRed = new int[6];
int UserSelectBule = 0;
int[] SystemSelectRed = new int[6];
int SystemSelectBule = 0;
int BuleCount = 0;//中奖蓝球数
int RedCount = 0;//中奖红球球
boolean flat = true;
System.out.println("双色球游戏开始:");
Scanner input = new Scanner(System.in);
/*以下为选号实现*/
//生成33个随机数字的数列
for(int i=0;i<33;i++)
RedBall[i]=i+1;
while(flat){
System.out.println("请选择机选数字/自选数字:1/2");
int IsAuto = input.nextInt();
Random r = new Random();
switch(IsAuto){
case 1:
SysSelectRed(RedBall,UserSelectRed);
UserSelectBule = r.nextInt(16);
flat = false;
break;
case 2:
UserRed(UserSelectRed);
while(UserSelectBule == 0){
System.out.println("请输入您选择的蓝球号码:");
int UserRedBall = input.nextInt();
if(UserRedBall<=16)
UserSelectBule = UserRedBall;
else System.out.println("输入有误,请重新输入");
}
flat = false;
break;
default:
flat = true;
}
}
/*以下为系统生成中奖号码*/
SysSelectRed(RedBall,SystemSelectRed);
Random r = new Random();
SystemSelectBule = r.nextInt(16);
/*以下为中奖号码匹配*/
for(int i =0;i<UserSelectRed.length;i++){
for(int j = 0;j<SystemSelectRed.length;j++)
if(UserSelectRed[i]==SystemSelectRed[j])
RedCount++;
}
if(UserSelectBule==SystemSelectBule)
BuleCount = 1;
/*以下为公布中奖情况*/
Arrays.sort(UserSelectRed);
Arrays.sort(SystemSelectRed);
System.out.print("中奖号码为:红球: ");
for(int x:SystemSelectRed)
System.out.print(x+" ");
System.out.println("蓝球: "+SystemSelectBule);
System.out.print("您的投注号码为:红球");
for(int x:UserSelectRed)
System.out.print(x+" ");
System.out.println("蓝球: "+UserSelectBule);
System.out.println("红球中奖个数为:"+RedCount+",蓝球中奖个数为:"+BuleCount);
}
//机选数字的方法
public static void SysSelectRed(int[] Ball,int[] SysSelect){
int p=-1; //用来放随机生成数的下标
Random r = new Random();
for(int i=0;i<SysSelect.length;i++){
p = r.nextInt(Ball.length-i);
int temp = Ball[p];
SysSelect[i]=temp;
Ball[p]=Ball[Ball.length-1-i];
Ball[Ball.length-1-i]=temp;
}
}
//自选数字方法
public static void UserRed(int[] UserRedNum){
Scanner input = new Scanner(System.in);
System.out.println("请输入您选择的红球号码:");
for(int i=0;i<UserRedNum.length;i++){
UserRedNum[i]=input.nextInt();
}
}
}
调试调了近一个小时,还是得多写/(ㄒoㄒ)/~~
命名等方面需规范