期中抽奖系统
2016-05-12 09:46 14软一2014330117刘哲 阅读(121) 评论(0) 编辑 收藏 举报import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
public class Game {
ArrayList<Integer> jiangquans;
public static void main(String[] args) {
// TODO Auto-generated method stub
Game g = new Game();
g.deal();
System.out.println("一等奖获得者:");
g.sj(1);
System.out.println("奖品是iPhone6s一部\n");
System.out.println("二等奖获得者:");
g.sj(2);
System.out.println("送奖金1000元\n");
System.out.println("三等奖获得者:");
g.sj(10);
System.out.println("手机话费100元");
}
private void sj(int i) {
// TODO Auto-generated method stub
}
public void deal(){
if(jiangquans == null){
jiangquans = new ArrayList<Integer>();
for(int i=1;i<=2000;i++){
jiangquans.add(i);
}
}
Collections.shuffle(jiangquans);}
public void sj1(int n){
Random ran1 = new Random(2000);
for (int i = 0; i < n; i++) {
int index = ran1.nextInt(jiangquans.size());
System.out.print(jiangquans.get(index)+"\t");
jiangquans.remove(index);
}
}
}
程序运行截图如下