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.
26 lines
853 B
26 lines
853 B
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();
|
|
}
|
|
}
|