zoukankan      html  css  js  c++  java
  • 第六次作业(修改后)

    package choujiang;

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

    public class cj {
    ArrayList list;
    static ArrayList b;
    public ArrayList addPerson(){
    if (list==null){
    list=new ArrayList();
    for(int i=1;i<=200;i++)
    list.add(i);

    	}
    	Collections.shuffle(list);
    	return list;
    }
    public void display(){
    	Random r=new Random();
    	int a=r.nextInt(200);
    	System.out.println("一等奖"+list.get(a)+"号");
    	list.remove(a);
    	for(int j=1;j<=10;j++){
    		a=r.nextInt(200);
    		System.out.println("二等奖"+list.get(a)+"号");
    		list.remove(a);
    	}
    }
    
    public static void main(String[] args) {
    	// TODO Auto-generated method stub
       cj a=new cj();
       a.addPerson();
      a.display();
    //  b=   a.addPerson();
      // System.out.println(b);
    }
    

    }
    该程序主要是对随机排列功能的实现,体现抽奖的随机性,用random和collection类的shuffle方法对list重新排列 ,将随机性加大

  • 相关阅读:
    centos vsftpd
    centos nginx
    linux 修改配色
    面试题讲解
    文件操作
    Python
    Python-linux作业
    python(12.17)笔记
    python周末作业(12.14--16)
    python作业(12.12)
  • 原文地址:https://www.cnblogs.com/yinxinlei/p/5484358.html
Copyright © 2011-2022 走看看