I'm trying to create a method produto to multiply matrices that will not be received by user input so I put a some matrices examples to test the code inside main. Right now I'm getting error "Syntax error on token "=", Expression expected after this token - line 15" Any help?
我正在尝试创建一个方法来将不会被用户输入的矩阵相乘,所以我用一些矩阵的例子来测试main里面的代码。现在,我正在获取错误“在令牌上的语法错误=”,在此令牌之后的表达式,第15行“有帮助吗?”
public class Mmul {
public static void main(String[] args) {
double[][] A={{1,2},{2,3}};
double[][] B={{1,2},{2,3}};
double[][] C={{0,0},{0,0}};
}
public void produto(double A[][], double B[][]){
int m=A.length; // numero de linhas da matriz A
int p=A[0].length; // numero de colunas da matriz A
int n=B[0].length; // numero de colunas da matriz B
double[][] C=[m][n];
if (A.length == 0 || B.length == 0) {
System.out.println("A matriz nao pode ser calculada.");
return;
if (B.length != p){
System.out.println("A matriz nao pode ser calculada.");
return;
}
for (int i=0; i<m; i++){
for (int j=0; j<n; j++){
for (int k=0; k<p; k++) {
C[i][j] += A[i][k]*B[k][j];
}
}
}
for (int i=0; i<C.length; i++){
for (int j=0; j<C.length; j++){
System.out.printf("\t %d \t",C[i][j]);
System.out.println();
}
}
} // fim da verificacao das matrizes
// codigo do metodo produto
}
}
}
2 个解决方案
#1
4
You need to assign to a type
您需要指定一个类型。
double[][] c = new double[m][n];
#2
0
should replace:
应该更换:
double[][] C=[m][n];
双C[][]=[m][n];
with
与
double[][] C=new double[m][n];
双C[][]= new双[m][n];
#1
4
You need to assign to a type
您需要指定一个类型。
double[][] c = new double[m][n];
#2
0
should replace:
应该更换:
double[][] C=[m][n];
双C[][]=[m][n];
with
与
double[][] C=new double[m][n];
双C[][]= new双[m][n];