彩票问题 不输出相同的数字
2016-01-15 22:02
218 查看
public class TestCar { public static void main(String[] args) { // TODO 自动生成的方法存根 int[] cp = new int[7]; Random r = new Random(); r.nextInt(36); for (int i = 0; i < cp.length; i++) { int t = r.nextInt(36); if(t == 0) { i--; continue; } else { boolean h = false; for(int c : cp) { if(c == t) { i--; h = true; break; } } if(h) { continue; } } cp[i] = t; } for (int c : cp) { System.out.print(c + " "); } } }
public class TestCar { public static void main(String[] args) { // TODO 自动生成的方法存根 int[] cp = new int[7]; Random r = new Random(); String str = ""; for (int i = 0;i <cp.length;i++) { int t = r.nextInt(36); if(t == 0) { i--; continue; } else { if(str.indexOf(""+t) >= 0) { i--; continue; } } str = str + t +" "; } System.out.print(str); } }
相关文章推荐
- C/C++小知识
- 1035
- Educational Codeforces Round 5 A. Comparing Two Long Integers
- Educational Codeforces Round 5 B. Dinner with Emma B. Dinner with Emma
- Educational Codeforces Round 5 C. The Labyrinth
- Educational Codeforces Round 5 D. Longest k-Good Segment
- 在知乎上给评论加入跳转链接--XSS练手
- MacBook外接显示器设置方法(新手入门贴)
- java加密、解密技术系列:Base64
- 网易新闻
- 针对之前的Canvas的一个小小的改版,算作canvas(二)吧
- 蓝懿IOS阶段测试
- 插入排序的一种尾递归实现-C
- UI_1
- python学习第十课续 :线程池
- linux变量篇(三) 命令行参数变量传递
- 怎样学习java?
- 开发中常见问题
- Ugly Number
- C#基础练习(时间的三连击)