zoukankan      html  css  js  c++  java
  • *随机6+1,开发实例

    package cn.com.yitong.test;

    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.Random;
    import java.util.Scanner;
    import java.util.Set;

    /*
    * 红球 1~33 篮球1-16
    */
    public class Demo {

    private static Set<Integer> set = new HashSet<Integer>();
    private static ArrayList<Integer> list = new ArrayList<Integer>();
    //private static int[] arr = new int[6];
    //private static int[] arrL = new int[7];
    private static int time = 0;
    private static Random random = null;
    private static int redBallMax=33;
    private static int blueBallMax=16;
    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.print("请输入注数:");
    int number = sc.nextInt();
    int count = 0;
    while (true) {
    count++;
    if (count > number) {
    break;
    }
    getRedBall();
    getBlueBall();
    getArr();
    }
    }

    /*
    * 从1-33个数字中随机取6个红球
    */
    public static void getRedBall() {
    random = new Random();
    int redNum = 0;
    while (true) {
    redNum = set.size();

    if (redNum >= 6) {
    break;
    }
    set.add(random.nextInt(redBallMax) + 1);
    // System.out.print(red+1+" ");
    }
    Iterator<Integer> iterator = set.iterator();
    // int s = 0;
    while (iterator.hasNext()) {
    int next = iterator.next();
    list.add(next);

    // arr[s] = next;
    // s++;
    }
    // Arrays.sort(arr);
    Collections.sort(list);
    set.clear();
    }

    /*
    * 从1-16中取1个篮球
    */
    public static void getBlueBall() {
    random = new Random();
    int count = 0;
    int blue = random.nextInt(blueBallMax) + 1;
    // arrL[6] = blue;
    list.add(blue);
    }

    // System.out.print(blue+1+" ");
    /*
    * 取出数组
    */
    public static void getArr() {
    time++;
    // int j = 0;
    // for (int i = 0; i < arr.length; i++) {
    // arrL[j] = arr[i];
    // j++;
    // }
    // /**
    // * 遍历数组arrL
    // */
    if (time > 1) {
    System.out.println();
    }
    // for (int i = 0; i < arrL.length; i++) {
    // if (arrL[i] >= 10) {
    // System.out.print(arrL[i] + " ");
    // } else {
    // System.out.print("0" + arrL[i] + " ");
    // }
    // }

    /* Iterator<Integer> iterator = list.iterator();
    while(true){
    int next = iterator.next();
    System.out.print(next+" ");
    }*/

    for(int i =0;i<list.size();i++){
    int next = list.get(i);

    if(next<10){
    System.out.print("0"+next+" ");
    }else{
    System.out.print(next+" ");
    }
    }
    list.clear();

    }

    }

    运行结果:

    请输入注数:10
    01 19 27 28 30 32 04
    04 05 16 24 25 28 10
    04 06 09 10 13 17 11
    01 02 10 13 21 24 05
    03 11 13 19 32 33 11
    05 07 10 18 24 27 05
    01 06 07 21 23 29 10
    09 10 17 21 22 24 11
    01 05 20 24 27 28 09

  • 相关阅读:
    路由交换03-----传输层协议
    Linux结构目录
    Linux RedHat 7 配置本地 YUM源
    HUAWEI,H3C 三层交换机 常用命令
    windows操作系统更改 <远程桌面> 端口号
    SpringBoot 2.x (2):请求和传参
    SpringBoot 2.x (1):手动创建项目与自动创建项目
    Eclipse中使用Maven搭建SSM框架
    基于Spring和Mybatis拦截器实现数据库操作读写分离
    WinServer配置MySQL主从同步
  • 原文地址:https://www.cnblogs.com/wpf-7/p/9646205.html
Copyright © 2011-2022 走看看