/**
*需要传递四个参数,分别是
* redmax 红球最大号码, red 红球需要开出的个数
* bulemax 篮球最大号码 ,bule 篮球需要开出的个数
*/
public void kai(int redmax,int red,int bulemax,int bule)
{
int[] name = new int[red];
int[] name2 = new int[bule];
lottery top = new lottery();
for(int i=0;i< name.length;i++)
{
name[i] = (int)(Math.random()* redmax +1);
for(int k=0;k<i;k++)
{
if(name[i] == name[k])
{
i--;
break;
}
}
}
for(int a=0;a< name2.length;a++)
{
name2[a] = (int)(Math.random()* bulemax +1);
for(int b=0;b<a;b++)
{
if(name2[a] == name2[b])
{
a--;
break;
}
}
}
lottery lot = new lottery();
name = lot.sort(name);
name2 = lot.sort(name2);
int[][] arrys = {name,name2};
for(int i = 0;i < arrys.length;i++)
{
if(i == arrys.length -1)
{
System.out.print("+++");
}
for(int j = 0;j < arrys[i].length;j++)
{
System.out.print("["+arrys[i][j]+"]");
}
}
}
/**
* 利用算法进行排序并返回排列好的数组
* @param sortid
* @return
*/
public static int[] sort(int array[])
{
//i表示第几轮“冒泡”,j 表示“走访”到的元素索引。
// 每一轮“冒泡”中,j 需要从列表开头“走访”到 array.length - 1 的位置。
for (int i = 0; i < array.length - 1; i++)
{
for (int j = 0; j < array.length - 1 - i; j++)
{
if (array[j] > array[j + 1])
{
int temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
return array;
}
模拟大乐透与双色球开奖
最新推荐文章于 2024-07-10 21:37:49 发布