1 public class Solution 2 { 3 public static void main(String[] args) 4 { 5 System.out.printf("%s\t%s\t%s\t%s\n", "Celsius", "Fahrenheit", "Fahrenheit", "Celsius"); 6 7 for(double i = 40, j = 120; i >= 31 && j >= 30; i--, j -= 10) 8 System.out.printf("%.1f\t%.2f\t%.1f\t%.2f\n", i, celsiusToFahrenheit(i), j, fahrenheitToCelsius(j)); 9 } 10 11 public static double celsiusToFahrenheit(double celsius) 12 { return (9.0 / 5) * celsius + 32; } 13 14 public static double fahrenheitToCelsius(double fahrenheit) 15 { return (5.0 / 9) * (fahrenheit - 32); } 16 }
时间: 2024-10-12 03:38:23