数组A{a,b,c,d}
数组B{A,B,C,D}
药实现aA+bB+cC+dD
你是要求数组A和数组B相同位置的元素相乘的和吗?下面是一个实现,result变量存储了它们的和,代码如下:
public class ArrayTest {
public class ArrayTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
double A[] = {1,2,3,4};
double B[] = {4,5,6,7};
double result = 0;
//double C[] = new double[A.length];
for(int i=0;i<A.length;i++) {
result += A[i]*B[i];
//C[i] = A[i]*B[i];
}
System.out.println("数组A和数组B相同位置元素相乘的和是:"+result);
}
}
int sum = 0;
for(int i=0; i++; i<A.length){
sum = sum+ A[i]*B[i];
}