ทักทายด้วยชื่อ
มีผู้ใช้แจ้งว่าอยากให้แอปทักทายพวกเขาด้วยชื่อ มาเพิ่มฟังก์ชันนี้เข้าไปใน custom method ของเรากัน
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Java ระดับกลาง
คำแนะนำการฝึกหัด
- กำหนดชนิดข้อมูลที่ถูกต้องให้กับอาร์กิวเมนต์
nameของspecificGreeter() - นำอาร์กิวเมนต์นั้นไปใช้ภายใน string เพื่อให้การทักทายเป็นแบบเฉพาะบุคคล
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
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);
}
}