62,621
社区成员
发帖
与我相关
我的任务
分享import java.math.*;
import java.util.Scanner;
public class LotteryGenerator {
static int randomInt(int x){
int ret;
do{
double getran = (10000*Math.random());
ret = (int)getran;
}while(ret>x || ret==0);
return ret;
}
static void run(int[] x,int[] y){
int i;
for(i=0;i<x.length;i++){
x[i] = randomInt(33);
}
y[0] = randomInt(16);
}
static void print(int[] x,int[] y,int z){
int length;
System.out.println("模拟开奖结果 " + z);
System.out.print("红球是:");
for(length=0;length<x.length;length++){
System.out.print(x[length] + " ");
}
System.out.println();
System.out.print("蓝球是:");
System.out.println(y[0]);
System.out.println("=====================");
}
static boolean check(int[] x){
boolean isIlleg = false;
int i=0,j=0;
for(i=0;i<x.length;i++){
for(j=0;j<x.length;j++){
if(x[i] == x[j]){
isIlleg = true;
}
}
}
return isIlleg;
}
static int input(){
Scanner s = new Scanner(System.in);
int i=0;
System.out.print("请输入开奖注数:");
i = s.nextInt();
System.out.println("=====================");
return i;
}
public static void main(String[] args) {
int[] general = new int[6];
int[] special = new int[1];
int i = input();
for(int c=0;c<i;c++){
do{
run(general,special);
}while(check(general));
java.util.Arrays.sort(general);
print(general,special,(c+1));
}
}
}do{
run(general,special);
}while(check(general));run(general,special);
static boolean check(int[] x){
boolean isIlleg = false;
int i=0,j=0;
for(i=0;i<x.length;i++){
for(j=0;j<x.length;j++){
if(x[i] == x[j]){
isIlleg = true;
}
}
}
return isIlleg;
} static boolean check(int[] x){
boolean isIlleg = false;
int i=0,j=0;
for(i=0;i<x.length-1;i++){ //循环数组长-1。
if(isIlleg){ //有重复,中断。
break;
}
for(j=i+1;j<x.length;j++){ //从上层循环的下一个数开始。
if(x[i] == x[j]){
isIlleg = true;
break; //检测有重复,中断内层循环。
}
}
}
return isIlleg;
}static int randomInt(int x) {
Random r = new Random();
return r.nextInt(x) + 1;//此方法返回0<=且<x之间的整数
}
static boolean check(int[] x) {
boolean isIlleg = false;
int i = 0, j = 0;
for (i = 0; i < x.length; i++) {
for (j = i + 1; j < x.length; j++) {
if (x[i] == x[j]) {
isIlleg = true;
}
}
}
return isIlleg;
}