當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java Fahrenheit轉Celsius用法及代碼示例

在這裏,我們將華氏溫度值轉換為攝氏溫度值。華氏和攝氏是溫度的度量單位,以度為單位oF 和oC分別。

公式

Celsius = (Fahrenheit - 32) / 1.8

方法

  1. 將華氏度的值初始化為 50.0,將攝氏度的值初始化為 0.0
  2. 使用上麵給出的公式計算攝氏度。
  3. 顯示攝氏溫度。

示例

Java


// Java Program to Convert Fahrenheit into Celsius
  
class fahrenheittocelsius {
    
    public static void main(String[] args)
    {
        // temperature in fahrenheit
        double fahrenheit = 50.0, celsius = 0.0;
  
        // calculate celsius temperature
        celsius = (fahrenheit - 32) / 1.8;
  
        // print the celsius temperature
        System.out.println(
            "value of temperature in celsius:" + celsius);
    }
}
輸出
value of temperature in celsius:10.0

時間複雜度:O(1)

相關用法


注:本文由純淨天空篩選整理自abhijithoyur大神的英文原創作品 Java Program to Convert Fahrenheit into Celsius。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。