产生10个随机数放入数组,不允许有重复

Posted 心忘则忘

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了产生10个随机数放入数组,不允许有重复相关的知识,希望对你有一定的参考价值。

import java.util.Arrays;


public class Random
public static void main(String[] args)
int a[] = new int[10];
a[0] = (int) (Math.random() * 10 + 1);
outer: for (int i = 1; i < 10; i++)
int t = (int) (Math.random() * 10 + 1);
for (int j = 0; j < 10; j++)
if (t == a[j])
i--;
continue outer;
 

a[i]=t;

        System.out.println(Arrays.toString(a));



以上是关于产生10个随机数放入数组,不允许有重复的主要内容,如果未能解决你的问题,请参考以下文章