I have this code:
public static int MAX;
public static int MIN;
public static void startGame(){
MIN = -1;
MAX = 1;
int[] randomGridVals = new int[ROWS*COLUMNS];
fill(randomGridVals);
System.out.println(Arrays.toString(randomGridVals));
<MORE CODE>
}
private static void fill(int[] randomGridVals) {
for(int i = 0 ; i < randomGridVals.length; i++)
{
int rnd = MIN + (int)(Math.random() * ((MAX - MIN) + 1));
randomGridVals[i] = rnd;
}
}
I expect that the array is passed by reference and the array have random values in it however when I try to print it its empty. Why is this happening ?
Hard to say for sure from the code you have provided. I would check the value of
ROWS*COLUMNS. That is probably 0 and thus you create a 0 sized array.