zoukankan      html  css  js  c++  java
  • 抽奖

    package homework;
    import java.util.*;

    public class choujiang{
    private HashSet<Integer> set;
    private Random rand;
    private Scanner sc;

    public choujiang() {
        set = new HashSet<>();
        rand = new Random();
        sc = new Scanner(System.in);
    }

    public void addToSet() {
        System.out.println("请输入总奖品数: ");
        int total = sc.nextInt();//total prize number
        while (set.size() < total) {
            set.add(rand.nextInt(1000));  //设置总共有多少个获奖
        }
    }

    public void drawPrize() {
        System.out.println("分别按顺序输入一二三等奖的获奖总数:");  
                                                                //分别设置每等奖的获奖人数
        int prize1 = sc.nextInt();//first prize number
        int prize2 = sc.nextInt();   
        int prize3 = sc.nextInt();


        Iterator iterator = set.iterator();
        int i = 0;
        System.out.println("获得一等奖的号码是 : ");
        while (i < prize1) {
            System.out.println(iterator.next());
            iterator.remove();
            i++;
        }
        i = 0;
        System.out.println("获得二等奖的号码是 :");
        while (i < prize2) {
            System.out.println(iterator.next());
            iterator.remove();
            i++;
        }
        i = 0;
        System.out.println("获得三等奖的号码是 :");
        while (i < prize3) {
            System.out.println(iterator.next());
            iterator.remove();
            i++;
        }
    }

    public static void main(String[] args) {
        choujiang setLearning = new choujiang();
        setLearning.addToSet();
        setLearning.drawPrize();
        }
    }

     

  • 相关阅读:
    Navigator is deprecated and has been removed from this package
    ES6 Promise
    SectionList的使用
    FastList使用
    react native touchable
    react native获取屏幕的宽度和高度
    RN导航栏使用
    2020-11-04:java里,总体说一下集合框架。
    2020-11-03:手写代码:链表如何快速找到中间节点?
    2020-11-02:go中,s:=make([]string,10);s=append(s,“test“);fmt.Println(s[0]),打印什么?
  • 原文地址:https://www.cnblogs.com/fanjiaming/p/5473705.html
Copyright © 2011-2022 走看看