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

在本文中,我们将通过一个示例向您展示如何编写一个 Java 程序将摄氏度转换为华氏度。转换公式为:华氏度 = (1.8 * 摄氏度) + 32。

下面的 Java 代码允许用户输入摄氏度温度。接下来,它使用上述公式将摄氏度 C 转换为华氏度 F。

package Remaining;

import java.util.Scanner;

public class CelsiusToFahrenheit {
	
	private static Scanner sc;
	
	public static void main(String[] args) {
		
		sc= new Scanner(System.in);

		System.out.print("Enter the Temperature in Celsius =  ");
		double celsius = sc.nextDouble();
		
		double fahrenheit = ((celsius * 9) / 5) + 32;
		//double fahrenheit = (1.8 * celsius) + 32;
		
		System.out.println("Temperature in Celsius    = " + celsius);
		System.out.println("Temperature in Fahrenheit = " + fahrenheit);		
	}
}
Program to Convert Celsius To Fahrenheit

让我在上面的 程序 中尝试不同的值。

Enter the Temperature in Celsius =  36
Temperature in Celsius    = 36.0
Temperature in Fahrenheit = 96.8