我有 2 个数组,每个数组包含 6 个不同的双数。添加两个数组以获得每个元素的平均值。然后产生 6 个平均数(数组 A 和数组 B 的每个元素相加然后除)现在我需要将计算出的这 6 个平均数相加,并得到这些平均数相加并除以 6 的结果。(对不起,如果我让人们感到困惑)我不知道如何开始。这是我的代码
public static void main (String [] args)
{
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);
computeResults(examMarks, 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();
}
public static void computeResults(double[] examMarks, double[] courseworkmarks)
{
double avgMarks[] =new double[examMarks.length];
System.out.println ("The total average of each module is ");
for(int i=0;i<avgMarks.length;i++){
int cwWeighting=40;
avgMarks[i]=(examMarks[i]*(100-cwWeighting)+courseworkmarks[i]*cwWeighting)/100;
System.out.print(avgMarks[i] + "\t" );
}
}
这是我迄今为止尝试过的:
public static computeStageMarks()
{
double totalMarks;
totalMarks = (avgMarks [])/6;
if (totalMarks<35)
{
System.out.println ("Failed" + totalMarks);
}
if (totalMarks>=40)
{
System.out.println ("Passed" + totalMarks);
}
if (totalMarks==35)
{
System.out.println ("Passed by compensation" + totalMarks);
}
但它不会工作。== 适合这种情况吗?我还需要它从最后一种方法中识别 avgMark。我该怎么做呢?