IniziaInizia gratis

Bollettino meteo

Hai trovato un modo per recuperare il bollettino meteo della tua posizione. Vuoi creare un piccolo programma che ti dica quale oggetto usare con i diversi tipi di tempo.

Questo esercizio fa parte del corso

Java intermedio

Visualizza il corso

Istruzioni dell'esercizio

  • Usa la parola chiave corretta per creare un case da verificare.
  • Inserisci la costante giusta per stampare solo quando è "Sunny".
  • Scrivi la parola chiave corretta per assicurarti che venga eseguito un solo println().

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