I'd like to know why I got these errors and how to fix it:
Main.java:12: error: '.class' expected
populateArray(int[] aRand);
^
Main.java:12: error: ';' expected
populateArray(int[] aRand);
The instructions I was given are in the comments and I just followed what I believe what the instructions meant. I thought maybe I should do populateArray();
in the main method, but it wouldn't match the signature of public void populateArray(int[] array){}
.
import java.util.Random;
public class Main {
public static void main(String args[])
{
/*
(a) Create an array of integers called aRand of capacity 20 and initialize its entries to 0.
*/
int aRand[] = new int[20];
populateArray(int[] aRand);
}
/*
(b) Populate the array in a method called populateArray(int[] array) where array is the one you want to populate.
This method returns void.
*/
public void populateArray(int[] array){
Random rand = new Random();
for (int i=0; i<array.length; i++){
array[i] = rand.nextInt();
System.out.println(array[i]);
}
}
}