Fill an array with random numbers

后端 未结 13 2219
感动是毒
感动是毒 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:41

    You can use IntStream ints() or DoubleStream doubles() available as of java 8 in Random class. something like this will work, depends if you want double or ints etc.

    Random random = new Random();
    
    int[] array = random.ints(100000, 10,100000).toArray();
    

    you can print the array and you'll get 100000 random integers.

    0 讨论(0)
提交回复
热议问题