从华氏温度到摄氏温度转换的Java代码如下。 该代码首先要求用户输入华氏度的温度,然后显示等效的摄氏温度。
/
package developer;
import java.util.Scanner;
public class FahrenheitToCelsius {
public static void main(String[] args) {
System.out.println("Enter a temperature in Fahrenheit: ");
Scanner scanFaren = new Scanner(System.in);
double Celsius = 0;
if(scanFaren.hasNextDouble())
{
Celsius = (scanFaren.nextDouble() - 32)*5/9;
}
System.out.println("The temperature in Celsius is: "+Celsius);
}
}
/
When this Java Code was executed on my JVM, then the output was as shown below.
/
Enter a temperature in Fahrenheit:
56
The temperature in Celsius is: 13.333333333333334
/
希望Java代码提供从华氏度到摄氏度的转换对大家有用。
From: https://bytes.com/topic/java/insights/881799-how-convert-fahrenheit-celsius