Fahrenheit to Celsius conversion yields only 0.0 and -0.0

后端 未结 5 1933
不思量自难忘°
不思量自难忘° 2020-12-02 01:06

I\'m on the 8th chapter (Methods, Constructors, and Fields) of my Java methods book and I\'m having a problem with one of my exercises.

The provided code is Tempera

5条回答
  •  执笔经年
    2020-12-02 01:27

    The problem seems to be 5/9. They are seen as an integer, and 5/9 is 0.something which is 0 as an integer. So whatever * 0 = +-0 :)

    Place a "d" after the numbers, (5d/9d) forcing the compiler to consider them doubles.

提交回复
热议问题