java 彩票大乐透 随机代码

public static void main(String[] args) {
        Set set = new HashSet();
        Set set2 = new HashSet();
        String[] a = {"01","02","03","04","05","06","07","08","09","10",
                "11","12","13","14","15","16","17","18","19","20",
                "21","22","23","24","25","26","27","28","29","30",
                "31","32","33","34","35"};

        String[] b = {"01","02","03","04","05","06","07","08","09","10",
                "11","12"};
        Random random = new Random();
        while (set.size() < 6){
            int num = random.nextInt(a.length);
            set.add(a[num]);
        }
        while (set2.size() < 3){
            int num = random.nextInt(b.length);
            set2.add(a[num]);
        }
        System.out.println("前五个号:"+set.toString());
        System.out.println("后两个号:"+set2.toString());
    }

你可能感兴趣的:(代码)