双色球与大乐透号码生成器

双色球

import java.util.*;

/**
 * Description:
 *
 * @author Lenovo
 * @date 2020/8/9
 **/
public class DoubleBallUtil {

    public static void getDoubleBall(int num) throws Exception {
        if (num <= 0) {
            System.out.println("请输入正确的注数!");
        }
        for (int i = 1; i <= num; i++) {
            System.out.print(String.format("第%s注-----",i));
            List redNumList = new ArrayList<>();
            while (redNumList.size() <= 5) {
                int redNum = (int) (Math.random() * 33 + 1);
                if (!redNumList.contains(redNum)) {
                    redNumList.add(redNum);
                }
            }
            Collections.sort(redNumList);
            Thread.sleep(888);
            int blueNum = (int) (Math.random() * 16 + 1);
            System.out.println(String.format("红球:%s  篮球:%s", redNumList, blueNum));
            Thread.sleep(888);
        }
    }


    public static void main(String[] args) throws Exception {
        getDoubleBall(2);
    }
}

大乐透

import java.util.*;

/**
 * Description:
 *
 * @author Lenovo
 * @date 2020/8/9
 **/
public class DaLeTouUtil {
    public static void getDaLeTou(int num) {
        if (num <= 0) {
            System.out.println("请输入正确的注数!");
        }
        for (int i = 1; i <= num; i++) {
            System.out.print(String.format("第%s注-----", i));
         
            List front = new ArrayList<>();
            
            List back = new ArrayList<>();
            
            while (front.size() < 5) {
                int a = (int) (Math.random() * 35 + 1);
                if (!front.contains(a)) {
                    front.add(a);
                }
            }
            
            Collections.sort(front);
            System.out.print(String.format("前排:%s  ", front));
            
            while (back.size() < 2) {
                int b = (int) (Math.random() * 12 + 1);
                if (!back.contains(b)) {
                    back.add(b);
                }
            }
            
            Collections.sort(back);
            System.out.println(String.format("后排:%s", back));
        }
    }

    public static void main(String[] args) {
        getDaLeTou(2);
    }
}

祝大家中大奖!
双色球与大乐透号码生成器_第1张图片

你可能感兴趣的:(笔记)