双色球案例

双色球案例

/*

  • 双色球案例
  • 红球和 蓝球
  • 蓝球 1个 1~16 之间
  • 红球 6个 1~33 之间
    /
    public class DoubleColorBall {
    public static void main(String[] args) {
    /
  • 先将 蓝球 摇出来
    */
    //Random类产生随机数
    Random rd = new Random();
    int blueBall = rd.nextInt(16)+1;
  /*
   * 完成红球的摇奖
   *   
   */
 //1:创建红球摇奖箱
  ArrayList<Integer> lotteryBox = new ArrayList<Integer>();
  //往摇奖箱中存储 33个球
  // 1~33
  for(int i = 1;i<=33;i++){
      lotteryBox.add(i);
  }
  //2:要开始摇奖了
  //摇奖之前 要完成 一个事情  创建一个 存储摇出来的红球的集合 
  
  ArrayList<Integer> redBox = new ArrayList<Integer>();
  
  //3总共要 摇奖6次
  for(int i =0;i<6;i++){
      //随机摇奖箱中索引    根据索引找到对应的球 在摇奖箱中删除 并且存储到摇奖红球集合中
      int index = rd.nextInt(lotteryBox.size());
      //index就是那个要被取出的红球的索引
      Integer randomBall = lotteryBox.get(index);
      
      //将这个球从 摇奖箱中删除掉
      lotteryBox.remove(randomBall);
      
      //存储到 红球集合中
      redBox.add(randomBall);

  }
 System.out.println("第171497期双色球:红球结果"+redBox);   
  
  System.out.println("蓝球:"+blueBall);

}
}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容