You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
559 B
16 lines
559 B
public class temperature {
|
|
public static double celsiusToFahrenheit(double c) {
|
|
return c * 9.0 / 5.0 + 32;
|
|
}
|
|
public static double fahrenheitToCelsius(double f) {
|
|
return (f - 32) * 5.0 / 9.0;
|
|
}
|
|
public static void main(String[] args) {
|
|
double c = 36.6;
|
|
double f = celsiusToFahrenheit(c);
|
|
System.out.printf("%.2f 摄氏度 = %.2f 华氏度\n", c, f);
|
|
double f2 = 98.6;
|
|
double c2 = fahrenheitToCelsius(f2);
|
|
System.out.printf("%.2f 华氏度 = %.2f 摄氏度\n", f2, c2);
|
|
}
|
|
}
|
|
|