2013-01-16 96 views
-3

所以基本上我試圖用9個值填充數組[]元素,但是我不知道如何獲得此代碼中的索引。我希望它每次都填充數組中的下一個元素。在java中填充數組

public boolean check(int data[][], int x, int y){ 
int array[] = new int[9]; 
int xmax = x+3; 
int ymax = y+3; 

     for(int i = x; i<xmax; i++){ 
      for(int j = y; j<ymax; j++){ 
       array[] = data[i][j];//array[what here?] 
      } 
     } 
} 
+1

通過什麼模式,你想數組值複製?我不確定你想要做什麼。 – Zyerah

+0

您正在循環2d數組並試圖填充1d數組?任何原因? –

+0

這個問題並不清楚,如果你想填充'array []'它應該在'='的左邊,並且對於索引你可以使用一個簡單的計數器變量 –

回答

1
for (int i = x; i < xmax; ++i) { 
    for (int j = y; j < ymax; ++j) { 
     array[3 * (i - x) + (j - y)] = data[i][j]; 
    } 
} 
+0

這就是我一直在尋找的感謝 – user1739261