矩阵是指纵横排列的数据表格,最早来自于方程组的系数及常数所构成的方阵,如: a11 a12... a1n a21 a22... a2n ... ... ... am1 am2... amn 矩阵乘积规则示例如下: 两个矩阵a和b可以相乘的条件是a矩阵的列数和b矩阵的行数相同,例如: 假设矩阵a为“3行2列”: a11 a12 a13 a21 a22 a23 矩阵b为“2行3列”: b11 b12 b21 b22 b31 b32 a和b可以相乘,乘积矩阵为: a11*b11+a12*b21+a13*b31 a11*b12+a12*b22+a13*b3 a21*b11+a22*b21+a23*b31 a21*b12+a22*b22+a23*b32 Matrix类的定义如下: public class Matrix { private double[][] data; private int rows; private int cols; public Matrix(int rows, int cols) { if (rows <= 0 || cols <= 0) throw new IllegalArgumentException("); this.rows = rows; this.cols = cols; data = new double[rows][cols]; } public Matrix(int rows, int cols, String line) { if (rows <= 0 || cols <= 0 || line == null) throw new IllegalArgumentException(""); String[] dataStr = line.split(","); if ( 空白处1 ) { throw new IllegalArgumentException(""); } this.rows = rows; this.cols = cols; data = new double[rows][cols]; for (int i = 0; i < dataStr.length; i++) { 空白处2 } } public Matrix mul(Matrix ma) { if ( 空白处3 ) { throw new IllegalArgumentException(""); } Matrix mc = new Matrix(rows, ma.cols); for (int i = 0; i < mc.getRows(); i++) { for (int j = 0; j < mc.getCols(); j++) { for ( 空白处4 ) { 空白处5 } } } return mc; } public int getRows() { return rows; } public int getCols() { return cols; } public String toString() { StringBuilder sb = new StringBuilder(); for (int i = 0; i < rows; i++) { for (int j = 0; j < cols - 1; j++) { sb.append(data[i][j]).append(","); } sb.append(data[i][cols - 1]).append("\n"); } return sb.toString(); } } 下列选项中,能填入空白处1的代码是( ) A. dataStr.length != (rows-1) * (cols-1) B. dataStr.length != (rows-1) * cols C. dataStr.length != rows * cols D. dataStr.length != rows * (cols-1) 37. 下列选项中,能填入空白处2的代码是( ) A. data[i % cols][i / cols] = Double.parseDouble(dataStr[i]); B. data[i/cols][i % cols] = Double.parseDouble(dataStr[i]); C. data[i/ rows][i % rows] = Double.parseDouble(dataStr[i]); D. data[i % rows][i /rows] = Double.parseDouble(dataStr[i]); 38. 下列选项中,能填入空白处3的代码是( ) A. cols != ma.cols B. rows != ma.cols C. rows != ma.rows D. cols != ma.rows 39. 下列选项中,能填入空白处4的代码是( ) A. int k = 0; k < cols; k++ B. int k = 0; k <ma.cols; k++ C. int k = 0; k <rows; k++ D. int k = 0; k <rows * ma.cols; k++ 40. 下列选项中,能填入空白处5的代码是( ) A. mc.data[i][j] += data[k][j] * ma.data[i][k]; B. mc.data[i][j] += data[k][i] * ma.data[j][k]; C. mc.data[i][j] += data[j][k] * ma.data[k][i]; D. mc.data[i][j] += data[i][k] * ma.data[k][j];
这个意思,关注一下
我晕 这不找人代做嘛