2.1(将摄氏温度转换为华氏温度)编写程序,从控制台读入double型的摄氏温度值,然后将其转换为华氏温度,并且显示结果。转换公式如下所示:
华氏温度 = (9 ÷ 5)× 摄氏温度 + 32
提示:在Java中,9/5的结果是1,但是9.0/5的结果是1.8。
下面是一个运行示例:
Enter a degree in Celsius:43.5
43.5 Celsius is 110.3 Fahrenheit
2.1(Convert Celsius to Fahrenheit) Write a program that reads a celsius in a double value from the console, converts it to fahrenheit, and displays the result. The formula for the conversion is as follows:
celsius = (9 ÷ 5) × fahrenheit + 32
Hint: In Java, the result of 9/5 is 1,but 9.0/5 is 1.8.
Here is a sample run:
Enter a degree in Celsius:43.5
43