[英]How do I create a method that meet this condition and return them?
如何创建一个具有大小为 x 的数组的方法,用 y 和 z 之间的随机数填充它,然后返回该数组? 当我调用该方法时,我将拥有特定大小的数组(x),然后我将拥有 z 和 y 的范围。
使用Random.ints(streamSize, origin, bound)
创建一个随机值的IntStream
,这些随机值被收集到数组中:
public static int[] buildArray(int size, int from, int to) {
return new Random() // or ThreadLocalRandom.current()
.ints(size, from, to) // IntStream
.toArray();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.