diff --git a/W1-王严笛-202506050329/Java源码.java b/W1-王严笛-202506050329/Java源码.java new file mode 100644 index 0000000..7914f83 --- /dev/null +++ b/W1-王严笛-202506050329/Java源码.java @@ -0,0 +1,38 @@ +import java.util.Scanner; +public class TemperatureConverter{ + public static double celsiusToFahrenheit(double celsius){ + return celsius * 9.0/5.0 + 32.0; + } + public static double fahrenheitToCelsius(double fahrenheit){ + return (fahrenheit - 32.0) * 5.0 / 9.0; + } + public static void main(String[] args){ + Scanner scanner = new Scanner(System.in); + System.out.print("请输入要转换的温度与单位:"); + String input = scanner.nextLine().trim(); + if (input.isEmpty()){ + System.out.println("输入为空,程序退出。"); + return; + } + try{ + double value = Double.parseDouble(parts[0]); + String unit = 'C'; + if (parts.length > 1){ + unit = parts[1].toUpperCase(); + } + if (unit.startsWith('C')){ + double f = celsiusToFahrenheit(value); + System.out.printf("%.1f℃ = %.2f℉%n",value,f); + } else if (unit.startsWith("F")){ + double c = fahrenheitToCelsius(value); + System.out.println("未知单位,请使用C或F。"); + } + } catch (NumberFormatExpectation e){ + System.out.println("输入解析失败,请按示例输入数值与单位。"); + } catch (Expectation e){ + System.out.println("输入格式错误,请检查输入。"); + } finally { + scanner,close(); + } + } +} \ No newline at end of file diff --git a/W1-王严笛-202506050329/README.md b/W1-王严笛-202506050329/README.md new file mode 100644 index 0000000..06d7405 Binary files /dev/null and b/W1-王严笛-202506050329/README.md differ diff --git a/W1-王严笛-202506050329/ai协助记录.txt b/W1-王严笛-202506050329/ai协助记录.txt new file mode 100644 index 0000000..06d7405 Binary files /dev/null and b/W1-王严笛-202506050329/ai协助记录.txt differ diff --git a/W1-王严笛-202506050329/image.png b/W1-王严笛-202506050329/image.png new file mode 100644 index 0000000..40de39d Binary files /dev/null and b/W1-王严笛-202506050329/image.png differ