zoukankan      html  css  js  c++  java
  • java第六次作业

    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Random;
    import java.util.*;
    public class choujiang {
        private ArrayList<Integer> cards;

        public void deal(int num){
            if (cards==null){
                cards=new ArrayList<Integer>();
                for(num=1;num<=100;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();
        }
    }

  • 相关阅读:
    MFC 将文件拖进对话框获得文件信息
    微软历史最高市值是多少?
    ZooKeeper的学习与应用
    OutputCache祥解
    本人的微博转移
    java list三种遍历方法性能比較
    VS2010旗舰版安装图解
    SSL协议具体解释
    freemarker字符串拼接
    [java web 入门](一)MyEclipse &amp; HelloWorld 记录
  • 原文地址:https://www.cnblogs.com/lkh960317/p/5498943.html
Copyright © 2011-2022 走看看