如何将数组添加到数组?

时间:2021-01-04 15:59:07

I've managed to get the marks from the exam and coursework to add up together and get an average. I realized this is what needs to happen.

我已经设法从考试和课程中得到了标记,以便加起来并获得平均分。我意识到这是需要发生的事情。

computed module mark = ((coursework mark * coursework weighting) + (examination mark * (100 - coursework weighting))) / 100

So, I need to make 2 arrays (if I'm correct), each having the weighting of each module, then do those calculations. How do I add an array to an array that already exists? This is what I have so far:

所以,我需要制作2个数组(如果我是正确的),每个数组都有每个模块的权重,然后进行这些计算。如何将数组添加到已存在的数组中?这是我到目前为止:

public static void main (String [] args)
{
    computeResults();
}
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();
    }
public static void computeResults()
{
     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;

        System.out.println(avgMarks[i]);
        }
}

}

1 个解决方案

#1


2  

It would be nice like this:

这样会很好:

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);
    System.out.println ("These are the final marks");
    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("\n");
    }


public static void computeResults(double[] examMarks, double[] courseworkmarks)
{

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

        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");
        }
}

#1


2  

It would be nice like this:

这样会很好:

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);
    System.out.println ("These are the final marks");
    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("\n");
    }


public static void computeResults(double[] examMarks, double[] courseworkmarks)
{

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

        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");
        }
}