• 随机产生13个0~51不同的随机数 -思想(定义参考系)


    1. /*
    2.  * 随机产生13个0~51没有重复的随机数
    3.  * class : arrayok
    4.  *
    5.  */
    6.  public class arrayok
    7.  {
    8.      public static void main(String args[])
    9.      {
    10.          int suit[] = new int[13]; //存储13个随机数

    11.          boolean sw[] = new boolean[52]; //随机数存在。则为真,否则为假

    12.          int key = 0;
    13.          for(int i = 0; i < suit.length; i++)
    14.          {
    15.              while(true)
    16.              {
    17.                  key = (int)(Math.random()*52);
    18.                  if(sw[key] == false){
    19.                      break;
    20.                  }
    21.              }
    22.              suit[i] = key;
    23.              sw[key] = true;
    24.          }
    25.          for(int i = 0; i < suit.length; i++)
    26.          {
    27.              System.out.print(suit[i]+" ");
    28.          }
    29.          System.out.print(" ");
    30.      }
    31.  }
  • 相关阅读:
    ==和equals的区别
    Java标准库定义的常用异常
    java.lang.ArithmeticException: / by zero
    类的设计
    预处理&枚举&其他
    内存管理
    指针和字符串
    指针
    数组
    流程控制语句
  • 原文地址:https://www.cnblogs.com/archermeng/p/7537618.html
Copyright © 2020-2023  润新知