import java.util.Scanner;
class Demo6 {
public static void main(String[] args) {
int[] red = new int[6];
int blu;
Demo6 sc = new Demo6();
//红色球中奖号码
for (int i = 0; i < red.length; i++) {
red[i] = (int)(Math.random()*33) +1;
}
//蓝色球中奖号码
blu = (int)(Math.random()*16)+1;
//客户选取号码
int[] myred = sc.Red();
int myblu = sc.Blu();
//客户红色球中奖个数
int redcount = sc.zhongRed(red, myred);
//客户蓝色球中奖个数
int blucount = sc.zhongBlu(blu, myblu);
//客户是否中奖
sc.guizhe(redcount, blucount);
System.out.print("红色球中奖号码为:");
for (int i = 0; i < red.length; i++) {
System.out.print(red[i] + "\t");
}
System.out.println();
System.out.println("蓝色球中奖号码为:" + blu);
System.out.print("您选取的红色号码为:");
for (int i = 0; i < myred.length; i++) {
System.out.print(myred[i] + "\t");
}
System.out.println();
System.out.println("您选取的蓝色号码为:" + myblu);
}
//客户选取红色球
public static int[] Red(){
Scanner sc = new Scanner(System.in);
int[] red= new int[6];
System.out.println("请您选取红色球:");
for (int i = 0; i < red.length; i++) {
red[i] = sc.nextInt();
while(true){
if ((red[i] > 33)||(red[i] < 1)) {
System.out.println("您输入的数字超出范围,请重新输入:");
red[i] = sc.nextInt();
}else{
break;
}
}
for (int j = 0; j <=(i-1); j++) {
if (red[i] == red[j]) {
System.out.println("您已经选取的此数据,请重新选择!");
i--;
}
}
}
return red;
}
//客户选取蓝色球
public static int Blu(){
Scanner sc = new Scanner(System.in);
System.out.println("请您选取蓝色球:");
int blu = sc.nextInt();
while(true){
if ((blu > 16)||(blu < 1)) {
System.out.println("您输入的数字超出范围,请重新输入:");
blu = sc.nextInt();
}else{
break;
}
}
return blu;
}
//客户红色球中了个数
public static int zhongRed(int[] red, int[] myred){
int count = 0;
for (int i = 0; i < red.length; i++) {
if (red[i] == myred[i]) {
count++;
}
}
return count;
}
//客户蓝色球是否中了
public static int zhongBlu(int blu, int myblu){
int count=0;
if (blu == myblu) {
count++;
}
return count;
}
//客户中奖情况
public static void guizhe(int red, int blu){
if (blu == 1) {
if (red == 6) {
System.out.println("一等奖");
}
else if (red == 5) {
System.out.println("二等奖");
}
else if (red == 4) {
System.out.println("三等奖");
}
else if (red == 3) {
System.out.println("安慰奖");
}
}else{
System.out.println("没中奖");
}
}
}
|
|