[英]cannot convert from int[] to double error java
I tried to understand related questions on stackoverflow but, no way. 我试图了解有关stackoverflow的相关问题,但是没有办法。 I'm new on java. 我是Java新手。
Have a problem like this: 有这样的问题:
Type mismatch: cannot convert from int[] to double
First error line, says: 第一个错误行说:
return sumVect(sumVect3(A,B,C),multVectMatrix(D,multMatrix(MA,MD)));
Second error line, says: 第二个错误行说:
E=F1(A, B, C, D, MA, MD);
And my T1.java
file 还有我的T1.java
文件
public class T1 extends Data implements Runnable{
protected T1(int N, int value) {
super(N, value);
}
public void run() {
int[][] MA, MD;
int[] A, B, C, D;
double E;
A = inputVector();
B = inputVector();
C = inputVector();
D = inputVector();
MA = inputMatrix();
MD = inputMatrix();
// Calculation F1
System.out.println("Calculator F1:....");
try {
E=F1(A, B, C, D, MA, MD);
System.out.println("F1:");
System.out.println("F1: " + E);
} catch (Exception f1) {
// TODO: handle exception
f1.printStackTrace();
}
}
private double F1(int[] A, int[] B, int[] C, int[] D, int[][] MA, int[][] MD )
{
return sumVect(sumVect3(A,B,C),multVectMatrix(D,multMatrix(MA,MD)));
}
And data.jav
file, may helps, so pasting here. 而data.jav
文件可能会data.jav
帮助,因此请粘贴到此处。
protected static int[][] multMatrix(int[][] MA, int[][] MB){
int[][] MT = new int[MA.length][MA.length];
for (int i = 0; i < MA.length; i++) {
for (int j = 0; j < MA.length; j++) {
int s = 0;
for (int k = 0; k < MA.length; k++) {
s += MA[i][k] * MB[k][j];
MT[i][j] = s;
}
}
}
return MT;
}
protected static int multVect(int[] A, int[] B){
int v=0;
for(int i =0;i<A.length;i++){
v+=A[i]*B[i];
}
return v;
}
protected static int[] sumVect(int[] A, int[] B){
int[] Z = new int [A.length];
for(int i =0;i<A.length;i++){
Z[i]=A[i]+B[i];
}
return Z;
}
protected static int[] sumVect3(int[] A, int[] B, int[] C){
int[] Z = new int [A.length];
for(int i =0;i<A.length;i++){
Z[i]=A[i]+B[i]+C[i];
}
return Z;
}
protected static int[] multVectMatrix(int[] A, int[][] MA){
int[] V = new int[A.length];
for (int i = 0; i < A.length; i++) {
int s = 0;
for (int j = 0; j < A.length; j++) {
s += A[j]*MA[i][j];
}
V[i] = s;
}
return V;
}
Your sumVect
method returns an array of int
( int[]
), but you are trying to return it in your F1
method, which should return a double
. 您的sumVect
方法返回一个int
( int[]
)数组,但是您试图在F1
方法中返回它,该方法应该返回double
。 You should figure out what each method should return and make your code consistent. 您应该弄清楚每种方法应该返回什么并使代码一致。
private double F1(int[] A, int[] B, int[] C, int[] D, int[][] MA, int[][] MD )
{
// here you are returning an int[] when you should return a double
return sumVect(sumVect3(A,B,C),multVectMatrix(D,multMatrix(MA,MD)));
}
your sumVect function returns an int[] table 您的sumVect函数返回一个int []表
and you F1() functions returns a double . 并且您F1()函数返回double。
You are probably have a typo 你可能有错字
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.