温度转换

来源:互联网 发布:非诚勿扰程序员不洗脸 编辑:程序博客网 时间:2024/04/27 15:43


题目内容:

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

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

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

提示,为了把计算结果的浮点数转换成整数,需要使用表达式:(int)x;

其中x是要转换的那个浮点数。

输入格式:

一个整数。

输出格式:

一个整数

输入样例:

100

输出样例:

37

时间限制:500ms内存限制:32000kb

Java程序

---------------

importjava.util.Scanner;

publicclass Main {

  public static void main(String[] args) {

     Scanner in = new Scanner(System.in);

     int f = in.nextInt();

     int c = (int)(5.0 / 9.0 * (f - 32));

     System.out.printf("%d\n", c);

  }

}

0 0
原创粉丝点击