How to create an array object in the main method in java? : <p>I've just started Java this semester and I'm very new to it. I'm struggling to get an array method to print out anything through my main method. The example given below is from the notes, except for the info in the main method which I added, but I cannot get it to print anything through the main method since it gives me an error every time I try to compile it. </p>

<p>This is the array method example that was given:</p>

<pre><code>import java.util.*;
</code></pre>

<p>import java.text.*;
public class ArrayDemo
{</p>

<pre><code>private static Random rng = new Random();  
private static DecimalFormat format =new DecimalFormat();
static{
    format.setMaximumFractionDigits(4); 
}

public static void main(String [] args){


    int num1 = 5; 
    arrayDemo(num1);

}



public void arrayDemo(int n){

    double [] a = new double[n]; 
    double [] c = {42, -99.9999, rng.nextGaussian() * 50};

    for (int i = 0; i &lt; a.length; i++){ 
        a [i] = rng.nextDouble(); 
    }

    double sum = 0;
    for (int i =0; i&lt; a.length; i++){

        sum += a[i];  
    }

    System.out.println("The values add up to" + format.format(sum));
    System.out.println("The elements are:" + Arrays.toString(a));
}







}
</code></pre>

<p>The error that I keep getting is "non static method arrayDemo(int n) cannot be referenced from a static context.".</p>

<p>I've searched up many tutorials on arrays but I still cannot figure out why I keep getting this error. Any help will be greatly appreciated.</p>
