-
随机产生13个0~51不同的随机数 -思想(定义参考系)
- /*
- * 随机产生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("
");
- }
- }
-
相关阅读:
==和equals的区别
Java标准库定义的常用异常
java.lang.ArithmeticException: / by zero
类的设计
预处理&枚举&其他
内存管理
指针和字符串
指针
数组
流程控制语句
-
原文地址:https://www.cnblogs.com/archermeng/p/7537618.html
Copyright © 2020-2023
润新知