import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
/**
* 彩票代码,系统
* */
public class Test {
static int BuleNum =0;
static int userBlueNum =0;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Random ran = new Random();
//用户输入的彩票
int[] userRedNum = new int[6];
for (int i = 0; i < userRedNum.length; i++) {
System.out.println("请您输入第"+(i+1)+"个红球号码:");
int num =sc.nextInt();
userRedNum[i]=num;
}
System.out.println("请您输入蓝球号码:");
int userBlueNum = sc.nextInt(); //用户的蓝球号码
System.out.print("用户输入的红球号码"+Arrays.toString(userRedNum)+" ");
System.out.println("用户输入的蓝球号码"+userBlueNum);
//系统彩票
int[] Redarr = new int[6];
int BuleNum =ran.nextInt(16)+1;
for (int i = 0; i < Redarr.length; i++) {
int num = ran.nextInt(33)+1;
if(!luckNum(Redarr,num)){
Redarr[i] =num;
}else{
i--;
}
}
System.out.print("系统的红球号码"+Arrays.toString(Redarr)+" ");
System.out.println("系统的蓝球号码"+BuleNum);
//第四步:统计中奖个数
//蓝球号码
int blueCount = BuleNum == userBlueNum ? 1 :0;
int redCount = 0;
for(int i : Redarr){
for(int j : userRedNum){
if(i == j){
redCount++;
}
}
}
System.out.println("红球中奖个数为:" + redCount+"个,蓝球中奖个数为:"+ blueCount+"个");
//第五步:公布中奖结果
if(redCount == 6 && blueCount==1){
System.out.println("恭喜您中了 一等奖!");
}else if(redCount == 6 && blueCount ==0){
System.out.println("恭喜您中了二等奖");
}else if(redCount ==5 || redCount ==4 && blueCount ==1){
System.out.println("恭喜您中了三等奖");
}
else if(redCount ==3 && blueCount ==1){
System.out.println("恭喜您中了三等奖");
}else if(redCount ==1 && blueCount ==1){
System.out.println("恭喜您中了四等奖");
}else{
System.out.println("很遗憾,您没有中奖!");
}
}
//判断随机号码是否重复
public static boolean luckNum(int[]arr,int lucknum ){
boolean flag = false;
for (int i = 0; i < arr.length; i++) {
if(arr[i]==lucknum){
flag =true;
}
}
return flag;
}
}
我来Show Show 大家可以看看 |