import java.util.ArrayList; import java.util.Collections; public class Cj { ArrayList<Integer> List; private int j; private int k; public void deal(){ if (List == null){ List = new ArrayList<Integer>(); for(int i=1;i<=200;i++){ List.add(i); } } Collections.shuffle(List); } public void draw(){ Random r = new Random(); int index = r.nextInt(List.size()); System.out.println("一等奖为:"+ List.get(index)); List.remove(index); for(j=0;j<2;j++){ int index1= r.nextInt(List.size()); System.out.println("二等奖为:"+List.get( index1)); List.remove(index1); } for(k=0;k<3;k++) { int index2 = r.nextInt(List.size()); System.out.println("三等奖为:"+List.get(index2)); List.remove(index2); } } public static void main(String[] args) { // TODO Auto-generated method stub Cj c = new Cj(); c.deal(); c.draw(); } }
时间: 2024-10-13 20:43:31