第六次作业
package choujiang;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public class choujiang {
ArrayList
public static void main(String[] args) {
// TODO Auto-generated method stub
choujiang cj = new choujiang();
cj.deal();
cj.action();
}
public void deal(){
if(number==null){
number = new ArrayList<Integer>();
for(int i=1;i<=100;i++){
number.add(i);
}
}
Collections.shuffle(number);
}
public void action(){
Random r = new Random();
//一等奖
int index =r.nextInt(number.size());
System.out.println("一等奖:"+number.get(index));
number.remove(index);
Collections.shuffle(number);
//二等奖
for(int i=0;i<2;i++){
int indextwo = r.nextInt(number.size());
System.out.println("二等奖:"+number.get(indextwo));
number.remove(indextwo);
}
Collections.shuffle(number);
//三等奖
for(int i=0;i<3;i++){
int indexthree = r.nextInt(number.size());
System.out.println("三等奖:"+number.get(indexthree));
}
}
}
运行出来的结果如下图:
出来的都是随机结果