/**
1、生成系统号码,6红1蓝
2、接收用户的选号 6红1蓝
3、验证号码的正确个数
4、公布中奖结果
*/
import java.util.Random;
import java.util.Scanner;
public class Test1{
public static void main(String[] args){
int[] sysRedBall = new int[6];//存储系统生成的红球
int sysBlueBall = 0;//存储系统生成的的蓝球
int[] userRedBall = new int[6];//存储用户选择的红球
int userBlueBall = 0;//存储用户选择的蓝球
int redCount = 0;//正确的红球个数
int blueCount = 0;//正确的蓝球个数
Random r = new Random();
int[] redBall = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33};
//游戏开始
System.out.println("双色球游戏开始,祝你好运!");
int index = 0;
//生成系统号码
for(int i=0;i<sysRedBall.length;i++){
while(true){
index = r.nextInt(33);
if(redBall[index]!=-1){
sysRedBall[i] = redBall[index];
redBall[index] = -1;
break;
}
}
}
sysBlueBall = r.nextInt(16)+1;
//接收用户选号
System.out.println("请选择红球号码(1-33)");
Scanner in = new Scanner(System.in);
for(int i=0;i<userRedBall.length;i++){
userRedBall[i] = in.nextInt();
}
System.out.println("请选择蓝球号码(1-16)");
userBlueBall = in.nextInt();
//验证是否中奖
for(int i=0;i<sysRedBall.length;i++){
for(int j=0;j<userRedBall.length;j++){
if(sysRedBall[i]==userRedBall[j]){
redCount++;
break;
}
}
}
if(sysBlueBall==userBlueBall){
blueCount++;
}
//判断是否中奖
if(redCount==6 && blueCount==1){
System.out.println("恭喜你,中了一等奖500万!");
}else if(redCount==6 && blueCount==0){
System.out.println("恭喜你,中了二等奖10万!");
}else if(redCount==5 && blueCount==1){
System.out.println("恭喜你,中了三等奖3000块!");
}else if(redCount==5 || (redCount==4 && blueCount==1)){
System.out.println("恭喜你,中了四等奖200块!");
}else if(redCount==4 || (redCount==3 && blueCount==1)){
System.out.println("恭喜你,中了五等奖10块!");
}else if(blueCount==1){
System.out.println("恭喜你,中了六等奖5块!");
}else{
System.out.println("谢谢你的支持,加油加油!");
}
//输出结果
for(int i=0;i<sysRedBall.length-1;i++){
for(int j=0;j<sysRedBall.length-1-i;j++){
if(sysRedBall[j]>sysRedBall[j+1]){
int temp = sysRedBall[j];
sysRedBall[j] = sysRedBall[j+1];
sysRedBall[j+1] = temp;
}
}
}
System.out.print("本期红球号码为:");
for(int i=0;i<sysRedBall.length;i++){
System.out.print(sysRedBall[i]+" ");
}
System.out.println();
System.out.println("本期的蓝球号码为:"+sysBlueBall);
}
}
|
|