第六次作业

package choujiang;

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

public class ChouJiang {
private ArrayList List;
public void deal(){
//向List容器中顺序添加指定数量num的整数
if (List == null){
List = new ArrayList();
for(int i =1;i<=50;i++){
List.add(i);
}
}
//打乱List中 元素的顺序
Collections.shuffle(List);
}
//抽奖的方法:抽出指定数量s的奖项
public void draw(){
Random rd = new Random();
int index = rd.nextInt(List.size());
System.out.println("获得一等奖的号码是:"+index);
List.remove(index);
Collections.shuffle(List);

	for(int i=0;i<2;i++){
		int index2 = rd.nextInt(List.size());
		System.out.println("获得二等奖的号码是:"+index2);
		List.remove(index2);
	}
	Collections.shuffle(List);
	for(int i=0;i<3;i++){
		int index3 = rd.nextInt(List.size());
		System.out.println("获得三等奖的号码是:"+index3 );
	}
}
public static void main(String[] args) {
	// TODO Auto-generated method stub
	ChouJiang cj = new ChouJiang();
	cj.deal();	
	cj.draw();
}

}

posted @ 2016-05-12 16:15  软二2014330208胡美玲  阅读(104)  评论(0编辑  收藏  举报