행렬에 곱하는 데 문제가 있습니다. 내 코드는 이처럼 생겼고 행렬 자체를 곱해야하지만 작동하지 않으며 이유가 없습니다.자체적으로 Java에서 행렬 곱하기
class Matrix {
// Constructor: create a matrix with only zeroes.
public Matrix(int numRows, int numColumns) {
this.values = new double[numRows][numColumns];
this.numRows = numRows;
this.numColumns = numColumns;
}
public int getNumRows() {
return this.numRows;
}
public int getNumColumns() {
return this.numColumns;
}
public double getValue(int row, int column) {
return this.values[row][column];
}
public void setValue(int row, int column, double value) {
this.values[row][column] = value;
}
public Matrix multiply(Matrix b) {
// to be implemented
int [][] result = new int[Matrix b.length][Matrix b[0].length];
for (int i = 0; i < Matrix b.length; i++) {
for (int j = 0; j < Matrix b[0].length; j++) {
for (int k = 0; k < Matrix b[0].length; k++) {
result[i][j] += Matrix b[i][k] * Matrix b[k][j];
}
}
}
return result
}
}
public void print() {
for (int i = 0; i < this.numRows; i++) {
for (int j = 0; j < this.numColumns; j++) {
System.out.print(this.values[i][j] + " ");
}
System.out.println();
}
}
private double[][] values;
private int numRows;
private int numColumns;
}
어떤 결과가 나타 납니까? – amaurya123
어떤 오류가 있습니까? 무슨 일 이니? 너 뭐 해봤 니? –
스팸 메일은 질문에 태그를 달지 말고 코드를 포맷하면 쉽게 읽을 수 있습니다. 그렇게 어렵지는 않으며 편집자가 자동으로 수행합니다. – Eldelshell