java 矩阵相乘

来源:百度知道 编辑:UC知道 时间:2024/05/27 08:21:02
public class Matrix {
int[][] a;
int[][] b;
public Matrix(int [][]x,int [][]y) {
int[][]a=x;
int[][]b=y;
}
public Matrix BiMatrix(){
int x=a.length;
int y=b[0].length;
int o=b.length;
int z[][]=new int[x][y];
for(int xx=0;xx<x;xx++){
for(int yy=0;yy<y;yy++){
int result=0;
for(int oo=0;00<o;oo++){
result=result+a[xx][oo]*b[oo][yy];
}

z[xx][yy]=result;

}
}

}
for(int xx=0;xx<x;xx++){
for(int yy=0;yy<y;yy++){
System.out.println(z[xx][yy]);
}

}

return z;

} 两个矩阵相乘,好像是返回值和方法的类型弄错了 编译报错,大侠救命啊!

public class test15 {
int[][] a;
int[][] b;
public test15(int [][]x,int [][]y) {
this.a=x;
this.b=y;
}
public void BiMatrix(){
int x=a.length;
int y=b[0].length;
int o=b.length;
int z[][]=new int[x][y];
for(int xx=0;xx<x;xx++){
for(int yy=0;yy<y;yy++){
int result=0;
for(int oo=0;00<o;oo++){
result=result+a[xx][oo]*b[oo][yy];
}

z[xx][yy]=result;

}
}

for(int xx=0;xx<x;xx++){
for(int yy=0;yy<y;yy++){
System.out.println(z[xx][yy]);
}

}

}
public static void main(String args[]){
int [][]x=new int[2][2];
x[0][0]=1;
x[0][1]=1;
x[1][0]=1;
x[1][1]=1;

int [][]y=new int[2][2];
y[0][0]=2;
y[0][1]=2;
y[1][0]=2;
y[1][1]=2;
test15 test=new test15(x, y);
test.BiMatrix();

}
}