Fill an array with random numbers

后端 未结 13 2227
感动是毒
感动是毒 2020-12-03 11:54

I need to create an array using a constructor, add a method to print the array as a sequence and a method to fill the array with random numbers of the type double.

He

13条回答
  •  既然无缘
    2020-12-03 12:23

    Probably the cleanest way to do it in Java 8:

    private int[] randomIntArray() {
       Random rand = new Random();
       return IntStream.range(0, 23).map(i -> rand.nextInt()).toArray();
    }
    

提交回复
热议问题