• 期中抽奖系统


    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Random;
    public class Game {

    ArrayList<Integer> jiangquans;
    

    public static void main(String[] args) {

    // TODO Auto-generated method stub

        Game g = new Game();
    
        g.deal();
    
        System.out.println("一等奖获得者:");
    
        g.sj(1);
    
        System.out.println("奖品是iPhone6s一部
    ");
    
        System.out.println("二等奖获得者:");
    
        g.sj(2);
    
        System.out.println("送奖金1000元
    ");
    
        System.out.println("三等奖获得者:");
    
        g.sj(10);
    
        System.out.println("手机话费100元");
    
         }
    
    private void sj(int i) {
    // TODO Auto-generated method stub
    
    }
    
    public void deal(){
    
     if(jiangquans == null){
    
      jiangquans = new ArrayList<Integer>();
    
      for(int i=1;i<=2000;i++){
    
       jiangquans.add(i);
    
      }
    
     }
    
     Collections.shuffle(jiangquans);}
    

    public void sj1(int n){

    Random ran1 = new Random(2000);

            for (int i = 0; i < n; i++) {
    
     int index = ran1.nextInt(jiangquans.size());
    
        System.out.print(jiangquans.get(index)+"	");
    
        jiangquans.remove(index);
    
               }
    

    }

    }

    程序运行截图如下

  • 相关阅读:
    mysql 常用函数
    JSP 分页代码
    day15(Mysql学习)
    day14(编码实战-用户登录注册)
    Bootstrap第3天
    Bootstrap第2天
    Bootstrap 第一天
    day13(JSTL和自定义标签&MVC模型&javaweb三层框架)
    label 对齐
    Alert提示框之后跳转指定页面
  • 原文地址:https://www.cnblogs.com/katne1995/p/5484514.html
Copyright © 2020-2023  润新知