int leccs1 = q1+q2+r1+swhw1;
System.out.println("LecCS = "+ leccs1+ "/60");
int lecprelim = lcp+lcpo;
System.out.println("LecPrelim = "+ lecprelim+ "/100");
double x = 0.50;
int lecgrade = ((x * leccs1) + (x * lecprelim));
System.out.println("LecGrade = "+ lecgrade);



C:\FINALS OBE\OBE1\ICS112_1ISB_LecFinals_OBE.java:61: error: possible loss of precision
    int lecgrade = ((x * leccs1) + (x * lecprelim));
                                 ^
  required: int
  found:    double
1 error

Process completed.


我正在尝试计算成绩。用户输入成绩作为输入。我希望x是double而不是int。

最佳答案

更改

   int lecgrade = ((x * leccs1) + (x * lecprelim));




double lecgrade = ((x * leccs1) + (x * lecprelim));

int grade=lecgrade.intValue();


或一行就可以写

int lecgrade = ((x * leccs1) + (x * lecprelim)).intValue();


使用intValue()double转换为int

检查intValue()

09-12 08:59