摄氏度和华氏度之间的额转换 Exercise06_08

时间:2021-08-01 04:22:11
 /**
* @author 冰樱梦
* 时间:2018年下半年
* 题目:摄氏度和华氏度之间的额转换
*
*/
public class Exercise06_08 {
public static void main(String[] args){
System.out.printf("%-23s%-22s%-20s%-10s","摄氏度","华氏度","华氏度","摄氏度");
System.out.println("\n————————————————————————————————————————————————");
for(double i=40,j=120;i>=31&&j>=30;i--,j-=10){
System.out.printf("%-10.1f%-10.1f%-10.1f%.1f\n",i,celsiusToFahrenheit(i),j,fahrenheitToCelsius(j));
} }
public static double celsiusToFahrenheit(double celsius){
return (9.0/5)*celsius+32;
}
public static double fahrenheitToCelsius(double fahrenheit){
return (5.0/9)*(fahrenheit-32);
}
}