HW5.8

时间:2023-01-03 20:48:14

HW5.8

 public class Solution
 {
     public static void main(String[] args)
     {
         System.out.printf("%s\t%s\t%s\t%s\n", "Celsius", "Fahrenheit", "Fahrenheit", "Celsius");

         for(double i = 40, j = 120; i >= 31 && j >= 30; i--, j -= 10)
             System.out.printf("%.1f\t%.2f\t%.1f\t%.2f\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); }
 }

相关文章