Bắt đầu ngayBắt đầu miễn phí

Weather Reporter

You've found a way to retrieve the weather report for your location. You want to have a small program that tells you what item to use in different types of weather.

Bài tập này là một phần của khóa học

Intermediate Java

Xem khóa học

Hướng dẫn bài tập

  • Use the correct keyword to make it a case to check.
  • Put in the right constant to print only when it is "Sunny".
  • Write the correct keyword down to make sure only one println() will take effect.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

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");
    }
  }
}
Chỉnh sửa và Chạy Mã