嗨即時創建一個Java程序的分數矩陣複用,我已經創建了一個類的分數,下面的代碼。矩陣乘法(分數)
public Fraccion (int n,int m){
numerador = n;
denominador = m;
}
接收分子和分母,在我的主要功能我收到矩陣的大小,創建矩陣的2x2 3x3的等等...和即時通訊目前得到預期的輸出 。 我的問題是本身multiplicating矩陣,(因爲that's我想要什麼)
,所以這是我的主類代碼
private static void transicion()
{
//size of matriz
Fraccion[][] tmp = new Fraccion[cuantos][cuantos];
//cloning the matrix to a temporal matrix
tmp = matrix.clone();
//set boundaries for matrix so dont go out of bounds
int rowLimit = matrix.length;
int colLimit = matrix[0].length;
for (int i = 0; i < matrix.length; i++)
{
for (int j = 0; j < matrix[i].length; j++)
{
//method to multiply a fraction with another (producto_con)
if ((j+1<colLimit) && (matrix[i][j] == matrix[i][j+1]))
matrix[i][j].producto_con(tmp[i][j+1]);
if ((i+1<rowLimit) && (matrix[i][j] == matrix[i+1][j]))
matrix[i][j].producto_con(tmp[i][j+1]);
System.out.println();
matrix[i][j].imprimete();
}
System.out.println();
}
}
//this is the method to multiply fractions on the fraction class
public Fraccion producto_con(Fraccion laOtra){
int numTmp, denTmp;
numTmp = numerator * laOtra.getnumerator();
denTmp = denominator * laOtra.getdenominator();
Fraccion laNueva = new Fraccion(numTmp,denTmp);
return laNueva;
}
但是當我打印方法transicion,打印相同的矩陣沒有變化,請提供任何幫助或建議?
但你永遠不會使用'return laNueva;'值? –