Q:

Array in java, with random number

I am trying to create and array that can store floating point numbers anywhere from 0.00 to 100.00. I am having a problem with the hArray, going back and fourth from it saying it needs to be initialized and trying numerous ways to do that, it tells me to change it to doublehArray[] = null;. but when i try that no valuse are stored in it. 
the problem occurs between line 3 and also line 27 which is hArray[i}] = rnum
Ignore the print line command i was just using those to check errors.
public static void main(String[] args) {
    int i;
    double hArray[];
    int nYears = 0, y = 0;
    double rMax = 0.00,rMin = 100.00;

    get input check if between 1-80
    while(y == 0){
    String userData = JOptionPane.showInputDialog
                               ("Enter number of years");
    nYears = Integer.parseInt(userData);

    if (nYears > 1 && nYears <= 80 )
        y = 1;

    }

     reset y to = 0
    y = 0;
    System.out.println("step1 "+ nYears+ " "+ y);
    while(y <= nYears){
        System.out.println("step2");
        for(i = 0; i < 12; i++){
            System.out.println("step3");
            Random rand = new Random();
            double rNum = rand.nextFloat() * (rMax - rMin) + rMin;
            hArray[i] = rNum;
            System.out.println("step4" + hArray[i]);
        }

A:

It is important to note some things in Java. First, this line is 'declaring a reference':
double hArray[];

All this does is say that there will be an array of type double and gives that array the name hArray. That array is not actually initialized. Then, at this line:
hArray[i] = rNum;

... rNum can't actually be put anywhere because the array doesn't exist.
You could do something like this at first to 'initialized' the array to length 12:
double[] hArray = new double[12];

Then the second line will work. Note that if you try to reference a location greater than 12 this will cause an error: the size of the list here is considered immutable.
Alternatively, you can get away from using primitives and use a Collection. In this case a List:
List<Double> hArray = new ArrayList<>();

And then, later:
hArray.add(rNum);

This prevents you from needing to know how big the array will need to be from the beginning. The List will autoscale. Also, it will not assume a default value: by initializing an array of primitives a default value equivalent to 0 will be placed in the array. Avoiding the use of primitives is considered to be a best practice.

