When I run the below code, I get error at res1 = Math.ceil((double) dividend / divisor);
Incompatible types: possible lossy conversion from double to int
However, I do not get the error when I do the same operation but this time add the result to an integer res1
.
res1 += Math.ceil((double) dividend / divisor);
Can someone pls help understand this more?
void func(int[] dividends , int divisor){
int res1 = 0;
for(int dividend : dividends){
res1 = Math.ceil((double) dividend / divisor); //error: incompatible types: possible lossy conversion from double to int
res1 += Math.ceil((double) dividend / divisor); //this works
print(res1);
}
}