我正在学习如何使用Java,在我的课程中,我被要求构建一个应用程序,该应用程序将读取考试标记和课程标记,然后将课程和考试标记的平均值打印到小数点后一位。当我将其提交到课程作业提交系统时,它说不正确。

它要求的答案是我的代码产生的答案(例如= 71 cw = 40马克= 55.5)
但是出于某种原因,当我提交它时它会这样说:

-#### << Differences between expected (<) your answer (>) >> ------------
1c1
< ex= 91 cw = 80 mark = 85.5
---
> ex = 71 cw = 40 mark = 55.5
-------------------------------------------------------------------------

[S] Sorry exercise ci101/1.2 was not correct.
Check the above output for why this attempt failed


当我将ex更改为91并将cw更改为80时,它再次要求> ex = 71 cw = 40 mark = 55.5。

class Main
{
  public static void main( String args[] )
  {
    int ExamMark=71;
    int CourseworkMark=40;

    double cost = (double)(ExamMark + CourseworkMark) / 2;

    System.out.printf("ex = " + ExamMark + " cw = " + CourseworkMark + " mark = " + cost);
    System.out.println();

  }

}

最佳答案

您可以将2-> 2.0设为两倍。

double cost = (ExamMark + CourseworkMark) / 2.0;

关于java - 计算两个整数的平均值并将其转换为Java中的double,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26676407/

10-10 19:44