Hi I am new to
Java, and I am trying to figure out the automatic conversion of float to double.
for example: double x = 39.21; float y = 2.1; c= x+y; the book said this will not compile because floating point literals are assumed to be double. So, if we wanted this to work we would have to initialize float y= 2.1f . But what I don,t understand is if y is automatically assumed to be a double , making x and y the same data type. Why does this code not compile?.
2) Also short x=14; float y=13; double z =30; c= x*y/z; here short is converted into an int and in the numeric operation x*y, 'x' gets converted to a float. My question is since float is not initialized with an f. shouldn't float value of y be assumed as a double and and hence in x*y shouldn't 'x' be promoted to a double instead of float ?
Could really use some help related to this. Thanks.