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.
23 lines
772 B
23 lines
772 B
import java.util.Scanner;
|
|
|
|
public class TemperatureConverter {
|
|
public static void main(String[] args) {
|
|
Scanner scanner = new Scanner(System.in);
|
|
|
|
System.out.println("请输入温度值:");
|
|
double value = scanner.nextDouble();
|
|
|
|
System.out.println("请输入单位(C表示摄氏度,F表示华氏度):");
|
|
String unit = scanner.next().toUpperCase();
|
|
|
|
if (unit.equals("C")) {
|
|
double f = value * 9.0 / 5.0 + 32.0;
|
|
System.out.println(value + "℃ = " + f + "℉");
|
|
} else if (unit.equals("F")) {
|
|
double c = (value - 32.0) * 5.0 / 9.0;
|
|
System.out.println(value + "℉ = " + c + "℃");
|
|
}
|
|
|
|
scanner.close();
|
|
}
|
|
}
|