java数组实现买彩票(重复则重新遍历查询思想)
2024-10-19 18:29:39
package com.wh.shuzu; import java.util.Arrays; /**
* 买彩票
* @author 丁璐同学
* 重复则重新遍历查询思想
*/
public class Lotery2 { public static void main(String[] args) {
int c[] = new int[5];
//先给数组全部赋值
for (int i = 0; i < c.length; i++) {
c[i] = (int) (Math.random() * 11 + 1);
}
//从第一个开始查询
for (int i = 0; i < c.length; i++) {
//从第二个开始查询
for (int j = i + 1; j < c.length; j++) {
//若相邻两个值重复,则给第二个元素重新赋一个随机数,并重新开始遍历查询是否有重复值
if (c[i] == c[j]) {
c[j] = (int) (Math.random() * 11 + 1);
i = 0;
j = i + 1;
} else {
continue;
} }
}
System.out.println(Arrays.toString(c)); }
}
最新文章
- jQuery外部框架浅析
- 当ListView有Header时,onItemClick里的position不正确
- 去哪儿网2017校招在线笔试(前端工程师)编程题及JavaScript代码
- swifter技巧(100)
- Lambda表达式之Python
- 12 Using_explain_plan
- u-boot 之配置分析 (2)
- POJ 3525 半平面交+二分
- 【原创】Linux下获取命令的帮助与常用命令
- iOS8 iPad Warning: Attempt to present <;UIImagePickerController:xxxx >; on xxxx which is already presenting (null)
- Spring Assert主张 (参议院检测工具的方法-主张)
- 运行指定路径下的exe
- Log4Net 常见格式说明(不断更新中)
- PHPNow升级PHP版本
- Windows10 中在指定目录下启动Powershell
- ubuntu代替方案
- centos7 部署 nginx+tomcat+MariaDB 环境并安装安全狗,使用natapp隧道
- Android java 多线程(三)
- MD5 加盐(Java)
- 【openjudge】【递推】例3.4 昆虫繁殖
热门文章
- ExpandableListView的使用以及信息的高亮显示
- Linux VPS/server上用Crontab来实现VPS自己主动化
- DB 查询分析器 6.03 ,遨游于不论什么Windows操作系统之上的最棒的数据库client工具
- 【转载】How browsers work--Behind the scenes of modern web browsers (前端必读)
- 深刻理解Java中形參与实參,引用与对象的关系
- http的session和cookie
- The uWSGI project aims at developing a full stack for building hosting services.
- netstat --numeric-ports -a -t -p 排查hadoop主从节点是否建立通信
- AOP 基本术语及其在 Spring 中的实现
- 并不对劲的bzoj2638