package test;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
public class PokerTest {
public static void main(String[] args) {
int[] poker = new int[52];
Set set = new LinkedHashSet();
//定义数组poker,并赋值
for (int i = 1; i <= 52; i++) {
poker[i - 1] = i;
}
//while循环向set集合里面插入poker中的数字,排除重复的数字。
while(true){
int in = new Integer((int)poker[(int) (Math.random() * 52)]);
System.out.println("添加的元素为:"+in);
set.add(in);
System.out.println("此时set元素个数为:"+set.size());
if(set.size()==52)
break;
}
//集合输出元素
for(Iterator iter=set.iterator();iter.hasNext();){
System.out.print(iter.next()+"\t");
}
}
}