码迷,mamicode.com
首页 > 其他好文 > 详细

第六次作业

时间:2016-05-24 19:11:59      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

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

public class ChouJiang {
private ArrayList cards;

    public void deal(int num){
    if (cards==null){
        cards=new ArrayList<Integer>();
        for(num=1;num<=40;num++){
            cards.add(num);
        }
    }
    Collections.shuffle(cards);
}
public void draw(){
    Random ra=new Random();
    int s =ra.nextInt(cards.size());
    System.out.println("一等奖:"+ cards.get(s));
    cards.remove(cards.get(s));
    Collections.shuffle(cards);
    
    for(int i=0;i<2;i++){
        int stwo=ra.nextInt(cards.size());
        System.out.println("二等奖"+ cards.get(stwo));
        cards.remove(cards.get(stwo));
        }
    Collections.shuffle(cards);
        for(int j =0;j<3;j++){
            int sthree =ra.nextInt(cards.size());
            System.out.println("三等奖"+cards.get(sthree));
                           cards.remove(cards.get(sthree));

        }

     }

public static void main(String[] args) {
    // TODO Auto-generated method stub
    ChouJiang c = new ChouJiang();
    c.deal(0);
    c.draw();
}

}

第六次作业

标签:

原文地址:http://www.cnblogs.com/mune/p/5524422.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!