(将摄氏溫度转换为华氏溫度)编写程序,从控制台读入double型的摄氏温度,然后将其转换为华氏温度,并且显示结果。转换公式如下所示:
华氏温度 = (9 / 5) * 摄氏温度 + 32
提示:在 Java 中,9/5 的结果是1, 但是 9.0/5 的结果是 1.83。
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package dome2_1;
import java.util.Scanner;
/**
*
* @author Administrator
*/
public class Dome2_1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner in = new Scanner(System.in);
System.out.print("Enter a degree in Celsius:");
double C = in.nextDouble();
double Fahrenheit = (9.0 / 5) * C + 32;
System.out.println(C + " Celsius is " + Fahrenheit +" Fahrenheit");
}
}