📌  相关文章
📜  将摄氏度转换为华氏度的Java程序

📅  最后修改于: 2022-05-13 01:55:06.976000             🧑  作者: Mango

将摄氏度转换为华氏度的Java程序

摄氏温标是基于0°C时水的冰点和100°C时水的沸点的温标。华氏温标是水的冰点为 32°F,水的沸点为 212°F 的温标。

例子:

Input : 0
Output: 32
Input :-40
Output:-40

方法:

  1. 将摄氏度值初始化为 10.0,将华氏度值初始化为 0.0
  2. 使用以下公式计算华氏度
  3. 华氏度=(摄氏度*1.8)+32;
  4. 显示华氏度。

下面是上述方法的实现:

Java
// Java Program to Convert Celsius into Fahrenheit
class celsiustofahrenheit {
    public static void main(String[] args)
    {
        // initialising
        double celsius = 10.0, fahrenheit = 0.0;
        
        // formula for conversion
        fahrenheit = (celsius * 1.8) + 32;
        System.out.println(
            " value of temperature in fahrenheit:"
            + fahrenheit);
    }
}


输出
value of temperature in fahrenheit:50.0

时间复杂度: O(1)

空间复杂度: O(1)