分组答辩小程序

package com.company;

import java.util.LinkedHashSet;
import java.util.Random;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
    // write your code here
        int[] array = new int[11];
        for(int i = 0; i < array.length; i++)
        {
            array[i] = i+1;
        }

        Random r = new Random();
        Set<Integer> sets = new LinkedHashSet<Integer>();
        while (true)
        {
            if(sets.size() == array.length)
                break;
            int nTemp = r.nextInt(array.length) + 1;
            sets.add(nTemp);

        }

        for(Integer i : sets)
        {
            System.out.println(i);
        }

    }
}

 

posted @ 2017-03-19 12:59  青春无语  阅读(346)  评论(0编辑  收藏  举报