复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19public static void main(String[] args) { // 每次重新随机完数据都要重第一个开始重新比较 // 随机生成十个不重复的数组元素 int []a=new int[10]; Random random=new Random(); int j=0; for (int i = 0; i <10 ; i++) { a[i]=random.nextInt(10); while(j<i){ for (j = 0; j <i; j++) { if (a[i]==a[j]) { a[i] = random.nextInt(10); break; } } } System.out.println(a[i]); } }
最后
以上就是舒心美女最近收集整理的关于随机生成十个不重复的数组元素的全部内容,更多相关随机生成十个不重复内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复