java - loss of precision-->Required double but compiler required int? -
i beginner in java , faced error.
write method named pay accepts real number ta's salary , integer number of hours ta worked week, , returns how money pay ta. example, call pay(5.50, 6) should return 33.0.
the ta should receive "overtime" pay of 1 ½ normal salary hours above 8. example, call pay(4.00, 11) should return (4.00 * 8) + (6.00 * 3) or 50.0.
public double pay(double x,int y){ int sum=0; double hours=8.0; if(y>hours){ sum=(y-hours)*(1.5*x) + (hours*x); } return sum; }
error:
you have mismatch between data types. occurs when try store real number (double) variable or parameter integer (int). possible loss of precision found : double required: int sum=(y-hours)*(1.5*x) + (hours*x); ^ 1 error 19 warnings
but error pointing @ + sign.what wrong it? says found:double. want output double. said required int.
since sum
int
, you're returning sum
in you're method, that's why error.
public double pay(double x,int y){ double sum=0; double hours=8.0; if(y>hours){ sum=(y-hours)*(1.5*x) + (hours*x); } return sum; }
for second error, if take @ class math, pi()
not exist, have call static variable of class math, should :
public double area(double x){ x=math.pi*math.pow(x,2); return x; }
Comments
Post a Comment