从基本类型int更改为类Integer

时间:2015-10-27 11:27:47

标签: java methods integer primitive-types

如何修改此方法以便使用类Integer而不是基本类型int

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;
}

1 个答案:

答案 0 :(得分: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;
}