gpt4 book ai didi

java - 如何将两个数组相加并得到总和的平均值?

转载 作者:行者123 更新时间:2023-12-02 06:33:49 27 4
gpt4 key购买 nike

我正在尝试将两个数组相加并得到总和的平均值我该怎么做呢?我也想在数组中生成答案。

public static void part1 (){

double examMarks [] = {50,40,60,80,70,11};
double courseworkmarks [] = {65,49,58,77,35,40};

System.out.println ("These are the exam marks and the course work marks");//First row is the exam marks, second row is the course work marks
computeMarks (examMarks);
computeMarks1 (courseworkmarks);

}
public static void computeMarks(double[] examMarks)
{
for (int row=0;row<examMarks.length;row++){
System.out.print (examMarks[row] +"\t");
}
System.out.println();
}
public static void computeMarks1(double[] courseworkmarks)
{
for (int row=0;row<courseworkmarks.length;row++){
System.out.print (courseworkmarks[row] +"\t");
}
System.out.println();
}

最佳答案

您可以尝试以下操作

    double examMarks [] = {50,40,60,80,70,11};
double courseworkmarks [] = {65,49,58,77,35,40};

double avgMarks[] =new double[examMarks.length];

for(int i=0;i<avgMarks.length;i++){
avgMarks[i]=(examMarks[i]+courseworkmarks[i])/2;
}

关于java - 如何将两个数组相加并得到总和的平均值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19851820/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com