用java做一个抽奖的代码

来源:百度知道 编辑:UC知道 时间:2024/06/24 23:05:28
1-35.每一次挑7个出来.
要求每次运行.结果中不能有重复的数字.
用记事本写。要能在cmd中直接运行..
要求是一组7个数中不能有一个重复的啊。
找随机数代码不就可能重复吗.

要在cmd下运行啊 我想你安装JDK没?

import java.util.*;
class Test{
private int maxSize=0;
private int selectSize=0;
private List<Integer> list=new ArrayList<Integer>();
private int[] one=new int[7];
public Test(int maxSize,int selectSize){
this.maxSize=maxSize;
this.selectSize=selectSize;
one=new int[selectSize];
for(int i=1;i<=maxSize;i++)
list.add(Integer.valueOf(i));
}

public void open(){
List<Integer> temp=new ArrayList<Integer>();
temp.addAll(list);
int[] p=new int[selectSize];
int tag=0;
for(int i=0;i<selectSize;i++){
tag=(int)(Math.random()*555555%temp.size());
p[i]=(Integer)temp.get(tag).intValue();
temp.remove(tag);
}
one=p;

}
public void paixu(){
int temp=0;
for(int i=0;i<selectSize;i++){
for(int j=0;j<selectSize-1;j++){
if(one[j