when integers are operated together with float or double, then it will be promoted to that type. the rules are as followed, int + float ---> float
int + double ---> double
int + float + double ---> double
int + double ---> double
int + float + double ---> double
而在于最初的赋值:
float c = 0.0;在Java中,小数的默认类型是 double
因此
float c = 0.0;
被Java编译器看成了 要将一个 double型 赋值给一个 float型
而且是要求自动转型
编译器当然不会支持所以,你将这句话改一下即可:float c = 0.0f;