对JAVA学习的一个星期。。。。
import java.util.Random;
import java.util.Scanner;
/**
1.系统随机产生红球和篮球
2.接收用户的输入
3.验证是否中奖
4.公布本期中奖号码
*/
public class doubleball
{
public static void main(String[] args)
{
int sysblueballnum;//系统产生蓝色球号码
int [] sysredballnum = new int [6];//系统产生红色球的号码
//用户的选择
int userblueballnum;
int [] userredballnum = new int [6];
//用于统计蓝色球和红色球中奖的个数
int blueball = 0;
int redball = 0;
Random r = new Random();
Scanner input = new Scanner(System.in);
//系统随机产生蓝色球和红色球的号码
sysblueballnum = r.nextInt(16)+1;//系统随机产生蓝色球号码
int [] redball2 = {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};//防止产生的红色球号码随机数重复
for (int i = 0;i<sysredballnum.length ;i++ )
{
while (true)
{
int b = r.nextInt(33);
if (redball2[b]!=0)
{
sysredballnum[i]=redball2[b];
redball2[b] = 0;
break;
}
}
}
//接收用户输入的蓝色球号码和红色球号码
System.out.println("---欢迎使用双色球彩票系统----");
System.out.print("请输入你要选择的蓝色球的号码(16选1):");
userblueballnum = input.nextInt();
System.out.println("请输入你要选择的红色球的号码(33选6)");
for (int i =0;i<sysredballnum.length ;i++)
{
userredballnum[i] = input.nextInt();
}
//验证是否中奖
if (userblueballnum == sysblueballnum)//验证蓝色球是否中奖
{
blueball = 1;
}
for (int i = 0;i<userredballnum.length ; i++)//验证红色球是否中奖
{
for (int j = 0;j<sysredballnum.length ;j++ )
{
if (userredballnum[i] == sysredballnum[j])
{
redball++;
break;
}
}
}
//中奖规则
if (redball==6 && blueball==1)
{
System.out.println("恭喜你中了一等奖,500万");
} else if (redball == 6)
{
System.out.println("恭喜你中了二等奖,150万");
} else if (redball == 5 && blueball == 1)
{
System.out.println("恭喜你中了三等奖,3000元");
} else if (redball == 5 || (redball == 4 && blueball == 1))
{
System.out.println("恭喜你中了四等奖,200元");
} else if (redball == 4 || (redball == 3 && blueball == 1))
{
System.out.println("恭喜你中了五等奖,10元");
} else if (blueball == 1)
{
System.out.println("恭喜你中了六等奖,5元");
} else
{
System.out.println("你丫人品弱爆啦!!!-_-! -_-! -_-! -_-! -_-!");
System.out.println("");
}
//公布中奖号码
int a=0;
System.out.println("下面公布本期中奖号码。。。");
System.out.println("本期蓝色球中奖号码是: "+sysblueballnum);
System.out.print("本期红色球中奖号码是:");
for (int i = 0;i <sysredballnum.length-1 ;i++ )//只用冒泡法排序,整理红球号码
{
for (int j = 0;j<sysredballnum.length-1-i ;j++ )
{
if (sysredballnum[j]>sysredballnum[j+1])
{
a = sysredballnum[j];
sysredballnum[j] = sysredballnum[j+1];
sysredballnum[j+1] = a;
}
}
}
for (int i =0;i<sysredballnum.length ;i++ )
{
System.out.print(sysredballnum[i]+" ");
}
System.out.println("");
System.out.println("谢谢使用本双色球彩票系统!");
}
}