开始使用免费开始使用

按名字打招呼

您收到反馈,用户希望应用能按名字打招呼。让我们把这个功能加到自定义方法里。

本练习是课程的一部分

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);
  }
}
编辑并运行代码