以名字打招呼
你收到回饋,使用者希望在 App 裡能以名字被問候。讓我們把這個功能加進自訂方法裡。
本練習屬於課程
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);
}
}