public static void main(String[] args) {
int[] winnums = new int[6];//系统随机生成的6位中奖号码球
int[] nums = new int[6];//用户红色号码球用数组nums[]存储
int userBlue;//用户蓝色号码球用变量blue存储
int winBlue;//系统生成的蓝色号码球
//随机生成1-33数字的6个红球
for (int i = 0; i < winnums.length; i++) {
winnums[i] = (int)(Math.random()*(33-1)+1);
}
//这一段代码用于展示系统生成的随机数,想看可以放开
/*System.out.print("(红色中奖号码):");
for (int i = 0; i < winnums.length; i++) {
System.out.print(winnums[i]+" ");
}System.out.println();*/
//随机生成1个蓝球
winBlue = (int)(Math.random()*(16-1)+1);
System.out.println("(蓝色中奖号码):"+winBlue);
Scanner input = new Scanner(System.in);
//记录用户输入的红色球
System.out.println("请输入6个红色号码球(1-33):");
for (int i = 0; i < nums.length; i++) {
nums[i] = input.nextInt();
}
//记录用户输入的蓝色球
System.out.println("请输入1个蓝色号码球(1-16):");
userBlue = input.nextInt();
int countBlue =0;
//比较系统和用户的蓝色球是否相等
if(userBlue==winBlue)
{
countBlue=1;
System.out.println("你蓝色球中了!");
}else {
System.out.println("你蓝色球没中");
}
//比较系统和用户的红色球是否相等
int countRed = 0;
for (int i = 0; i < nums.length; i++) {
for (int j = 0; j < nums.length; j++) {
if(nums[j]==winnums[i]) {
countRed++;
break;
}
}
}
System.out.println("你红色球中奖个数为:"+countRed);
if(countBlue==1&&countRed==0) {
System.out.println("恭喜你!中了六等奖!");
}
else if(countRed==1&&countBlue==1) {
System.out.println("恭喜你!中了六等奖!");
}
else if(countRed==2&&countBlue==1) {
System.out.println("恭喜你!中了六等奖!");
}
else if(countRed==3&&countBlue==1) {
System.out.println("恭喜你!中了五等奖!");
}
else if(countRed==4&&countBlue==0) {
System.out.println("恭喜你!中了五等奖!");
}
else if(countRed==4&&countBlue==1) {
System.out.println("恭喜你!中了四等奖!");
}
else if(countRed==5&&countBlue==0) {
System.out.println("恭喜你!中了四等奖!");
}
else if(countRed==5&&countBlue==1) {
System.out.println("恭喜你!中了三等奖!");
}
else if(countRed==6&&countBlue==0) {
System.out.println("恭喜你!中了二等奖!");
}
else if(countRed==6&&countBlue==1) {
System.out.println("恭喜你!中了一等奖!");
}
else {
System.out.println("很遗憾,你没有中奖!");
}
}
Java实现双色球
最新推荐文章于 2024-07-26 12:28:02 发布