java第六次作业(老师讲过后)
import java.util.*;
public class Draw {
private ArrayList
public Draw() {
list= new ArrayList
}
public void deal(int num) {
//向容器中添加奖券(使用循环)
for (int j = 0; j<= num ; j++) {
list.add(j);
}
//打乱顺序
Collections.shuffle( list);
}
public void drawLottery(int n){
Random ra = new Random();
for(int i=0;i<n;i++){
int index =ra.nextInt(list.size());
System.out.print(list.get(index)+"\t");
list.remove(index);
}
System.out.println();
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Draw c = new Draw();
c.deal(100);
System.out.println("————————一等奖————————");
c.drawLottery(2);
System.out.println("————————二等奖————————");
c.drawLottery(5);
System.out.println("————————三等奖————————");
c.drawLottery(10);
}
}