We already know that the return type of Math.lang() function in java is double.
class Lossy {
public static void main(String args[]) {
int sum;
sum=Math.pow(2,3);
System.out.println (sum);
}
}
Now this statement results in possible lossy conversion error because the variable is of type int and Math.pow() return a double value i.e. 8.0 which is fair enough.
Now look at the code below with some changes.
class Lossy {
public static void main(String args[]) {
int sum=2;
sum+=Math.pow(2,3);
System.out.println (sum);
}
}
Now if we compile this code we don't get an error of possible conversion error, which we should get because we are storing a double value in an integer variable. Moreover, when we are printing the value it shows an integer value. Why?