提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
随机整数数组
/* from N o w J a v a . c o m - 时 代 Java*/ //package com.nowjava; import java.util.HashSet; import java.util.Random; public class Main { public static void main(String[] argv) { int size = 42; System.out.println(java.util.Arrays.toString(randomIntArray(size))); } public static Integer[] randomIntArray(int size) { Integer a[] = new Integer[size]; HashSet<Integer> set = new HashSet<>(); for (int x = 0; x < a.length; x++) { Random r = new Random(); Integer i = r.nextInt(size * 10);/**from 时代Java - N o w J a v a . c o m**/