import java.util.Scanner;
public class temperature {
//1、℃摄氏=5/9(°F-32)2、华氏°F=℃×9/5+32
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
System.out.print("要转换的是华氏度还是摄氏度?(华氏度填1,摄氏度填2):");
int a = scan.nextInt();
double c,f;
switch (a) {
case 1 -> {
System.out.print("请输入要转换的华氏度:");
f = scan.nextDouble();
c = (5.0 / 9) * (f - 32);
System.out.print("摄氏度为:" + c);
}
case 2 -> {
System.out.print("请输入要转换的摄氏度:");
c = scan.nextDouble();
f = c * (9.0 / 5) + 32;
System.out.print("华氏度为:" + f);
}
}
}
}
Java实现摄氏度与华摄度的转换
最新推荐文章于 2023-09-26 14:51:28 发布