开始使用免费开始使用

天气播报员

您已经找到了获取当前位置天气预报的方法。现在,您想编写一个小程序,根据不同天气给出应该使用的物品。

本练习是课程的一部分

Java 中级

查看课程

练习说明

  • 使用正确的关键字,将其写成需要检查的 case
  • 填入正确的常量,使其只在 "Sunny" 时打印。
  • 写上正确的关键字,确保只有一个 println() 会生效。

交互式实操练习

通过完成这段示例代码来试试这个练习。

class WeatherReporter {
  public static void main(String[] args) {
    String weather = "Sunny";

    switch (weather) {
      // Use the correct keyword to make it a case to check
      ____ "Windy":
        System.out.println("Take an umbrella");
        break;
      // Enter the appropriate name to check for sunny
      case "____":
        System.out.println("Don't forget your sunscreen");
        // Write the correct keyword down to make sure the message will be unique
        ____;
      case "Cloudy":
        System.out.println("The umbrella might be great");
        break;
      default:
        System.out.println("I don't know what the weather will be like");
    }
  }
}
编辑并运行代码