• java双色球


    数组方法

    import java.util.Random;
    
    public class DoubleColorRandom {
    
        public static void main(String[] args) {
            Random r = new Random();
            int[] redNumber = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
                    26, 27, 28, 29, 30, 31, 32, 33 };
            int[] redNum = new int[6];
            int a = 0;
            int b = 0;
            System.out.println("红球号码为:");
            for (int i = 0; i < redNum.length; i++) {
                //
                while (true) {
                    a = r.nextInt(33);
                    System.out.print(a+" ");
                    //判断是否重复取数
                    if (redNumber[a] != 0) {
                        redNum[i] = redNumber[a];
                        redNumber[a] = 0;
                        System.out.print(redNum[i] + "	");
                        break;
                    }
                }
            }
            // 排序
            for (int i = 6; i > 0; i--) {
                for (int j = 1; j < i; j++) {
                    if (redNum[j - 1] > redNum[j]) {
                        redNum[j - 1] = redNum[j - 1] + redNum[j];
                        redNum[j] = redNum[j - 1] - redNum[j];
                        redNum[j - 1] = redNum[j - 1] - redNum[j];
                    }
                }
    
            }
            System.out.println();
            System.out.println("排序输出红球号码:");
            for (int i = 0; i < redNum.length; i++) {
                System.out.print(redNum[i] + "	");
            }
    
            System.out.println();
    
            b = r.nextInt(16) + 1;// 随机得到篮球号码
            System.out.println("蓝球号码为:" + "	" + b);
    
        }
    
    }

    集合

    package com.newer.cn;
    
    import java.util.ArrayList;
    import java.util.Random;
    
    public class DoubleBalls {
    
        public static void main(String[] args) {
            //实例化球池
            ArrayList<String> pools = new ArrayList<String>();
            //创建集合保存从球池中取出的球
            ArrayList<String> balls = new ArrayList<String>();
            //产生随机数
            Random random = new Random();
            for(int i = 1;i <= 33;i++){
                if(i < 10){
                    pools.add("0"+i);
                }else{
                    pools.add(""+i);
                }
            }
            System.out.println(pools);
            //取红球
            int randNum = 0;
            for(int i = 0;i < 6;i++){
                randNum = random.nextInt(pools.size());
                balls.add(pools.get(randNum));
                pools.remove(randNum);
            }
            System.out.println(balls);
            System.out.println(pools);
        }
    
    }
  • 相关阅读:
    Windows服务的安装及配合定时器编写简单的程序
    关于VS2019使用Git时遇到的Bug
    记一次工作中的小BUG
    .Net WebApi接口Swagger集成简单使用
    kettle 创建数据库资源库
    C# 语法 i++;++i;i--;--i
    MSDN
    Jenkins持续集成(下)-Jenkins部署Asp.Net网站自动发布
    Jenkins持续集成(上)-Windows下安装Jenkins
    自动发布-asp.net自动发布、IIS站点自动发布(集成SLB、配置管理、Jenkins)
  • 原文地址:https://www.cnblogs.com/lujing-newer/p/6556020.html
Copyright © 2020-2023  润新知