1 changed files with 0 additions and 26 deletions
@ -1,26 +0,0 @@ |
|||||
import java.util.Scanner; |
|
||||
|
|
||||
public class TemperatureConverter { |
|
||||
public static void main(String[] args) { |
|
||||
Scanner sc = new Scanner(System.in); |
|
||||
|
|
||||
System.out.println("=== 温度转换程序 ==="); |
|
||||
System.out.print("请输入温度值:"); |
|
||||
double value = sc.nextDouble(); |
|
||||
|
|
||||
System.out.print("请输入单位(C/F):"); |
|
||||
String unit = sc.next(); |
|
||||
|
|
||||
if (unit.equalsIgnoreCase("C")) { |
|
||||
double f = value * 9 / 5.0 + 32; |
|
||||
System.out.printf("%.2f℃ = %.2f℉%n", value, f); |
|
||||
} else if (unit.equalsIgnoreCase("F")) { |
|
||||
double c = (value - 32) * 5 / 9.0; |
|
||||
System.out.printf("%.2f℉ = %.2f℃%n", value, c); |
|
||||
} else { |
|
||||
System.out.println("输入错误!请输入 C 或 F"); |
|
||||
} |
|
||||
|
|
||||
sc.close(); |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue