始める無料で始める

名前であいさつしよう

ユーザーがアプリで名前付きのあいさつを望んでいるというフィードバックがありました。カスタムメソッドにその機能を追加しましょう。

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

中級 Java

コースを見る

演習の手順

  • specificGreeter() の引数 name に正しい型を指定します。
  • 文字列の中でその引数を使い、パーソナライズされたメッセージにします。

実践的なインタラクティブ演習

このサンプルコードを完成させて、この演習に挑戦してみましょう。

class Greeter {
  // Give the correct type to the argument of the method
  static void specificGreeter(____ name) {
    // Call the correct variable given as an argument to the method
    System.out.println("Nice day to you, " + ____ + "!");
  }

  public static void main(String[] args) {
    String firstName = "Caleb";
    specificGreeter(firstName);
  }
}
コードを編集して実行