2015-10-27 69 views
0

更改我怎麼能修改此方法,以便類Integer代替原始類型int從基本類型int到Integer類

int[][] fillMatrix() { 
    int[][] matrix = new int[5][4]; 
    for (int row = 0; row < 5; row++) 
     for (int column = 0; column < 4; column++) 
      matrix[row][column] = row * column; 
    return matrix; 
} 
+4

重寫你的代碼並用Integer替換int? – Stultuske

+0

你爲什麼想這樣做? – ControlAltDel

+0

@ControlAltDel他可能需要矩陣中的空值? – StackFlowed

回答

0

這個怎麼樣?

Integer[][] fillMatrix() { 
Integer[][] matrix = new Integer[5][4]; 
for (int row = 0; row < 5; row++) 
    for (int column = 0; column < 4; column++) 
     matrix[row][column] = row * column; 
return matrix; 
} 
+1

添加評論指出自動裝箱會讓我很多快樂 – ControlAltDel