Get startedGet started for free

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.

This exercise is part of the course

Intermediate Java

View Course

Exercise instructions

  • 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.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

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");
    }
  }
}
Edit and Run Code