IniziaInizia gratis

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.

Questo esercizio fa parte del corso

Intermediate Java

Visualizza il corso

Istruzioni dell'esercizio

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

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

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");
    }
  }
}
Modifica ed esegui il codice