双色球程序
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;
public class SSQ {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s ="
请输入你要的组数:
";
System.out.println(s);
int num = 0;
boolean b = true;
while(b){
try{
num = sc.nextInt();
if(num !=0){
for(int i=0;i<num;i++){
create();
}
}else{
s="
请输入非零数据
";
System.out.println(s);
}
}catch(InputMismatchException e){
System.out.println(e.getMessage());
b=false;
}
}
}
//
产生方法
public static void create(){
String[] red = getBar(6,34);
String[] blue = getBar(1,17);
Arrays.sort(red);
for(int i=0;i<red.length;i++){
System.out.print(red[i]+" ");
}
System.out.println("+ "+blue[0]);
}
//
产生需要的数据
public static String[] getBar(int number,int maxNum)
{
String[] s = new String [number];
Random rd = new Random();
for(int j=0;j<number;j++){
boolean flag = true;
while(flag){
int num = rd.nextInt(maxNum);
String n=AddZero(num);
if("00".equals(n)){
flag = true;
}else{
if(j==0){
s[j]=n;
flag = false;
}else{
boolean same = false;
for(int k=0;k<j;k++){
if(s[k].equals(n)){
same = true;
}
}
if(!same){
s[j] = n;
flag = false;
}
}
}
}
}
return s;
}
//
小于零的时候要加上0
public static String AddZero(int s){
String result = "";
if(s<10){
result="0"+s;
}else{
result = String.valueOf(s);
}
return result;
}

浙公网安备 33010602011771号