如何将Java从int转换为double?

如何将Java从int转换为double?,java,Java,我真的需要帮助从int转换为double。根据这个问题,他们想让我写一个公式,用除法和打字法计算出三个等级的平均值 这是到目前为止我的代码,我不知道为什么它保持在int模式。5号需要帮助。谢谢 public class Challenge1_6 { public static void main(String[] args){ // 1. Declare 3 int variables called grade1, grade2, grade3 /

我真的需要帮助从int转换为double。根据这个问题,他们想让我写一个公式,用除法和打字法计算出三个等级的平均值

这是到目前为止我的代码,我不知道为什么它保持在int模式。5号需要帮助。谢谢

    public class Challenge1_6
    {

     public static void main(String[] args){
   
   // 1. Declare 3 int variables called grade1, grade2, grade3
   // and initialize them to 3 values

       int grade1 = 90;
       int grade2 = 100;
       int grade3 = 94;

   // 2. Declare an int variable called sum for the sum of the grades
   int sum;

  // 3. Declare a variable called average for the average of the grades
    int avg;
  // 4. Write a formula to calculate the sum of the 3 grades (add them up).
    sum = grade1 + grade2 + grade3;

  // 5. Write a formula to calculate the average of the 3 grades from the sum using division and type casting.
       avg =  sum / 3;
  
   
   

  // 6. Print out the average
      System.out.println((double)(avg));
替换

int avg;
avg =  sum / 3;

或者

double avg =  (double) sum / 3;

它仍然说我没有通过任务。它想让我制作一个代码,其中包含三个等级的平均值公式,使用求和和和类型转换来加倍表示失败的是什么?一些自动评分系统?这个答案中给出的第二个解决方案使用“sum”和“casting to double”,并将给出正确的结果94.66…你不可能成为互联网上第一个遇到这个问题的人。请在发布问题之前进行研究。我道歉。但回答这个问题与否取决于你自己。不要在这里继续卑鄙。像其他人一样,如果你想帮助我,那就这么做。如果没有,那就不要。这是互联网,这篇文章本身不会占用你的个人空间。如果是这样,那么我道歉。对不起,但我不认为要求你遵守本网站的规则是卑鄙的。@TommyMai-如果我表现得卑鄙,那我就错了,我不是故意的。但是就像NomadMaker提到的,我们希望每个人都遵守网站的规则。这是否回答了你的问题?
double avg =  (double) sum / 3;