populate Double Array with random double value - Java Collection Framework

Java examples for Collection Framework:Array Random Value

Description

populate Double Array with random double value

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) {
        int numberOfItems = 42;
        System.out.println(java.util.Arrays
                .toString(populateDoubleArray(numberOfItems)));
    }/* w  ww  .  j av a  2 s.c  o m*/

    public static Double[] populateDoubleArray(int numberOfItems) {
        final String partialWord = "partialArrayParallel";
        Double[] dummyDoubleArray = null;
        if (numberOfItems > 0) {
            dummyDoubleArray = new Double[numberOfItems];
            for (int i = 0; i < numberOfItems; i++) {
                final double randomNumber = (Math.random() * numberOfItems);
                dummyDoubleArray[i] = randomNumber;
            }
        }
        return dummyDoubleArray;
    }
}

Related Tutorials