ทบทวนรายชื่อผู้ได้รับรางวัลโนเบล
จำรายชื่อผู้ได้รับรางวัลโนเบลสาขาฟิสิกส์จากแบบฝึกหัดก่อนหน้าได้ไหม? คราวนี้คุณต้องการเปลี่ยนมาใช้ชื่อ Heisenberg แทน Fermi จึงต้องอัปเดตข้อมูลที่บันทึกไว้
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Java เบื้องต้น
คำแนะนำการฝึกหัด
- เปลี่ยน element ที่สามของ
nobelLaureatesเป็น"Heisenberg" - เปลี่ยน element ที่สามของ
yearsเป็น1932 - เติมคำสั่ง print ให้สมบูรณ์เพื่อแสดง element สุดท้ายของทั้งสองอาร์เรย์
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
class NobelForPhysicsLaureatesRevisited {
public static void main(String[] args) {
String[] nobelLaureates = {"Curie", "Einstein", "Fermi"};
int[] years = {1903, 1921, 1938};
// Replace Fermi with Heisenberg
____[____] = "Heisenberg";
// Correct the year
years[____] = ____;
System.out.println(nobelLaureates[0] + " won in " + years[0]);
System.out.println(nobelLaureates[1] + " won in " + years[1]);
// Print the last record
System.out.println(nobelLaureates[____] + " won in " + ____[____]);
}
}