I am having an output problem with my java code. I am trying to implement this multiply matrix method and it compiles just fine. The only problem is my output. I seem to be getting the following:
---- Test Multiply Matrix ----
[[D@7f31245a
Should return C={{ 3, 2},{ 1, 1}}
Can someone please help me understand where I am going wrong here. Thanks! Here is my source code:
public class Recommendation
{
public static double[][] multiplyMatrix(double[][] A, double[][] B)
{
int aRows = A.length;
int bRows = B.length;
int aColumns = A[0].length;
int bColumns = B[0].length;
if((aColumns != bRows))
{
return null;
}
else
{
double[][] C = new double[aRows][bColumns];
for (int i = 0; i < 2; i++)
{
for (int j = 0; j < 2; j++)
{
C[i][j] = 0;
}
}
for (int i = 0; i < aRows; i++)
{
for (int j = 0; j < bColumns; j++)
{
for (int k = 0; k < aColumns; k++)
{
C[i][j] += A[i][k] * B[k][j];
}
}
}
return C;
}
}
static double [][] A = {{ 1, 0, 2},
{ 0, 1, 1}};
static double [][] B = {{1, 2},
{ 0, 1},
{ 1, 0}};
public static void main(String[] argss)
{
// TEST multiplyMatrix
System.out.println(" ---- Test Multiply Matrix ---- ");
System.out.println(multiplyMatrix(A,B)); // should return C={{ 3, 2},{ 1, 1}}
System.out.println("Should return C={{ 3, 2},{ 1, 1}}");
System.out.println(" ");
}
}