java抽奖程序

package choujiang;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class choujiang {

ArrayList number;

public ArrayList deal(){
if(number==null){
number=new ArrayList();
for(int i=1;i<1000;i++){
number.add(i);
}
}
Collections.shuffle(number);
return (number);
}

public void display(){
Random r=new Random();
int a=r.nextInt(1000);
System.out.println("一等奖是:"+number.get(a)+"号");
number.remove(a);
Collections.shuffle(number);

for(int j=1;j<=2;j++){
    a=r.nextInt(1000);
    System.out.println("二等奖是:"+number.get(a)+"号");
    number.remove(a);
    
    
}

for(int j=1;j<=3;j++){
    a=r.nextInt(1000);
    System.out.println("三等奖是:"+number.get(a)+"号");
    number.remove(a);
    }

}

public static void main(String[]args){
choujiang g =new choujiang();
g.deal();
g.display();
}

}

posted @ 2016-05-12 09:26  2014330112李杰  阅读(454)  评论(0编辑  收藏  举报