我有這樣的代碼:Java數組傳遞通過引用
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;
}
}
我想到的是,數組通過引用傳遞和陣列有它的隨機值然而,當我嘗試打印其空。這是爲什麼發生?
「空」,因爲在沒有條目? – 2012-01-27 23:47:49
yes打印[] – Cemre 2012-01-27 23:48:31
MIN和MAX的值是多少? – 2012-01-27 23:48:36