Java基础__随机生成1~15之间不重复的数字
2024-09-01 10:14:29
package text; import java.util.ArrayList;
import java.util.List; public class Text { public static void main(String[] args) {
//创建一个Integer集合的链表
List<Integer> l = new ArrayList<Integer>();
//当链表种存在15个数时结束像链表种插入数据
while(l.size()<15){
int i = (int)(Math.random()*15+1);
if(!l.contains(i))
l.add(i);
}
//迭代,输出链表中的元素
//for(int j:l)
// System.out.println(j);
for(int i=0;i<l.size();i++)
{
System.out.println(l.get(i));
} }
}
输出:(答案不唯一,随机数)
8
15
10
14
9
3
6
11
5
13
4
7
12
1
2
最新文章
- navigationController 去掉背景图片、去掉底部线条
- linux(centos)用户与权限
- Linux学习历程(持续更新整理中)
- 远程登录,无法加载explorer
- 两台笔记本搭建openvswitch网络
- MSSQLSERVER数据库- 杂记
- Queues 队列
- python中金额计算的小问题
- CentOs 系统启动流程相关
- zabbix3.2源码搭建
- 为什么要进行URL编码
- 区块链共识机制(POW、POS、DPOS等)的优缺点
- 微信小程序开发工具中快捷键
- CBSN NEWS
- 网络I/O模型---同步异步阻塞非阻塞之惑
- beego 初体验 - 基础模块 - config, httplibs, logs
- 网络(socket)编程
- (C/C++学习笔记) 五. 常变量(只读变量)和宏
- windows下能搭建php-fpm吗 phpstudy
- 软件工程github使用小结