Java日志
第六篇
抽奖
package choujiang;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public class lotterDraw {
public static void main(String[] args) {
ArrayList <Integer> number = new ArrayList<>();
Random random = new Random();
for (int i=0;i<1000;i++){
int a=i;
number.add(a);
}
Collections.shuffle(number);
int a =random.nextInt(1000);
System.out.println("一等奖"+number.get(a)+"
");
number.remove(a);
for(int i=1;i<=2;i++){
Collections.shuffle(number);
int b =random.nextInt(999-i);
System.out.println("二等奖"+number.get(b)+"
");
number.remove(b);
}
for(int i=1;i<=3;i++){
Collections.shuffle(number);
int c=random.nextInt(997-i);
System.out.println("三等奖"+number.get(c)+"
");
}
// TODO Auto-generated method stub
}
}