如何将华氏转换为摄氏

从华氏温度到摄氏温度转换的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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值