- /*
- * 随机产生13个0~51没有重复的随机数
- * class : arrayok
- *
- */
- public class arrayok
- {
- public static void main(String args[])
- {
- int suit[] = new int[13]; //存储13个随机数
- boolean sw[] = new boolean[52]; //随机数存在。则为真,否则为假
- int key = 0;
- for(int i = 0; i < suit.length; i++)
- {
- while(true)
- {
- key = (int)(Math.random()*52);
- if(sw[key] == false){
- break;
- }
- }
- suit[i] = key;
- sw[key] = true;
- }
- for(int i = 0; i < suit.length; i++)
- {
- System.out.print(suit[i]+" ");
- }
- System.out.print("\n");
- }
- }
转载于:https://www.cnblogs.com/archermeng/p/7537617.html