写一个将华氏温度转换成摄氏温度的程序

发布时间:2020-03-27 23:19:12   来源:文档文库   
字号:

写一个将华氏温度转换成摄氏温度的程序,转换的公式是:

°F=(9/5)*°C +32

其中C表示摄氏温度,F表示华氏温度。

程序的输入是一个整数,表示华氏温度。输出对应的摄氏温度,也是一个整数。

提示,为了把计算结果的浮点数转换成整数,需要使用下面的表达式:(int)x其中x是要转换的那个浮点数。

代码如下

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

// TODO Auto-generated method stub

int f;

Scanner in= new Scanner(System.in);

f = in.nextInt();

System.out.println((int)((f-32)/(9/5.0)));

}

}

本文来源:https://www.2haoxitong.net/k/doc/b2766ec7fb0f76c66137ee06eff9aef8941e4886.html

《写一个将华氏温度转换成摄氏温度的程序.doc》
将本文的Word文档下载到电脑,方便收藏和打印
推荐度:
点击下载文档

文档为doc格式