作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经设法将考试和类(class)作业的分数加起来并得出平均分。我意识到这就是需要发生的事情。
computed module mark = ((coursework mark * coursework weighting) + (examination mark * (100 - coursework weighting))) / 100
所以,我需要创建 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]);
}
}
}
最佳答案
像这样就好了:
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");
}
}
关于java - 如何向数组添加数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19852502/
我是一名优秀的程序员,十分优秀!