作业帮 > 综合 > 作业

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

来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/05/16 10:09:31
用JAVA写一个将华氏温度转换成摄氏温度的程序
程序的输入是一个整数,表示华氏温度.输出对应的摄氏温度,也是一个整数.
提示,为了把计算结果的浮点数转换成整数,需要使用下面的表达式:
(int)x;其中x是要转换的那个浮点数.
将华氏温度转换成摄氏温度的Java程序如下:import java.util.Scanner;

public class Fahrenheit {

 public static void main (String []args) {

     Scanner input =new Scanner(System.in);

  System.out.print("Enter a degree in Fahrenehit: ");

  int Fahrenehit= input.nextInt();

     int Celsius= (int)((Fahrenehit-32)*(5.0/9));

     System.out.println(Fahrenehit + " Fahrenehit is "+ Celsius + " Celsius");

 }

}运行结果:Enter a degree in Fahrenehit: 50
50 Fahrenehit is 10 Celsius