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

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

    public class choujiang {
    private ArrayList list;

    public void deal(){
    	//向list容器中添加指定数量num的整数
    	
    	if (list == null){
    		list = new ArrayList<Integer>();
    		for(int i=1;i<=100;i++){
    			list.add(i);
    			
    		}
    	}
    	
    	//打乱list中的元素的顺序
    	Collections.shuffle(list);
    }
    //抽奖的方法:指出指定数量S的奖项
    public void draw(){
    	Random rd = new Random(); 
    	int index1 =rd.nextInt(list.size());
    	System.out.println("获得一等奖的号码是:"+list.get(index1));
    	list.remove(index1);
    	Collections.shuffle(list);
    	int index2 =rd.nextInt(list.size());
    	System.out.println("获得二等奖的号码是:"+list.get(index2));
    	list.remove(index2);
    	Collections.shuffle(list);
    	int index3 =rd.nextInt(list.size());
    	System.out.println("获得三等奖的号码是:"+list.get(index3));
    	
    	
    }
    
    public static void main(String[] args) {
    	// TODO Auto-generated method stub
    	choujiang cj = new choujiang();
    	cj.deal();
    	cj.draw();
    
    }
    

    }

  • 相关阅读:
    局部组件
    flex布局
    Websocket
    关于Javascript夜里再来分析下
    go build、go mod等命令
    websocket
    FileSystemWatcher使用
    DataGridView双缓冲
    C#读INI文件
    c 通过 COM接口调用 Excel.Application 问题终于解决
  • 原文地址:https://www.cnblogs.com/www123/p/5486127.html
Copyright © 2011-2022 走看看