数组与循环_彩票6+1
/*
双色球 彩票 6+1位
*/
public class RandomAndAry{
public static void main(String[] args){
for(int i=1;i<=20;i++){
RandomAry();
}
}
//排序
public static void sortAry(int[] ary){
int temp=0;
//最多执行ary.length-1轮
for(int i=0;i<ary.length;i++){
//
for(int j=0;j<ary.length-1-i;j++){
if(ary[j]>ary[j+1]&&ary[j+1]!=0){
temp=ary[j];
ary[j]=ary[j+1];
ary[j+1]=temp;
}
//System.out.print(j+"\t");
}
}
}
public static void RandomAry(){
int[] ary = new int[7];
for(int i =0;i<ary.length-1;i++){
ary[i] = (int)(Math.random()*33+1);
for(int j=0;j<i;j++){
if(ary[i]==ary[j]){
ary[i] = (int)(Math.random()*33+1);
j-=1;
continue;
}
}
}
sortAry(ary);
ary[ary.length-1] = (int)(Math.random()*16+1);
for(int i=0;i<ary.length;i++){
System.out.print(ary[i]+",");
}
System.out.println();
}
}