始める無料で始める

Weather Reporter

現在地の天気予報を取得できるようになりました。天気の種類に応じて、どのアイテムを使うべきかを教えてくれる小さなプログラムを作りたいと考えています。

この演習はコースの一部です

中級 Java

コースを見る

演習の手順

  • 判定したい値に対して case を作るため、正しいキーワードを使ってください。
  • "Sunny" のときだけ出力するよう、適切な定数を入れてください。
  • 1 回だけ 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");
    }
  }
}
コードを編集して実行