DESKTOP-0FT47VC_20200910-罗贤丞

问题

实现体育彩票大乐透号码生成器。

解决

public class DaLeTou {
    public String toString(int[] y) {
        if (y == null) {
            return null;
        }
        StringBuilder b = new StringBuilder();
        for (int i = 0; i < y.length; i++) {
            if (y[i] > 9) {
                b.append(y[i]);
            } else {

                b.append("0");
                b.append(y[i]);
            }
            b.append(" ");

        }
        return b.toString();
    }

    public static void main(String[] args) {
        DaLeTou d = new DaLeTou();
        int[] a = new int[5];
        int[] b = new int[2];
        Random r = new Random();
        loop: for (int i = 0; i < a.length; i++) {
            a[i] = r.nextInt(34) + 1;
            for (int j = 0; j < i; j++) {
                if (a[i] == a[j]) {
                    i--;
                    continue loop;
                }
            }

        }
        loop: for (int i = 0; i < b.length; i++) {
            b[i] = r.nextInt(12) + 1;
            for (int j = 0; j < i; j++) {
                if (b[i] == b[j]) {
                    i--;
                    continue loop;
                    
                }
            }
        }
        System.out.println(d.toString(a) + "" + d.toString(b));
    }

}

吐槽

很热很难受。

标签

© 2021 成都云创动力科技有限公司 蜀ICP备20006351号-1