ผู้ชนะทั้งหมด
เมื่อทำงานกับข้อมูลที่มีหลายรายการ สิ่งสำคัญคือต้องรู้ว่ามีข้อมูลอยู่กี่ชิ้น อาร์เรย์มีวิธีตรวจสอบขนาดที่ใช้งานง่าย ซึ่งมีประโยชน์มากในการประมวลผล ตรวจสอบความถูกต้อง และสรุปผล มาลองวัดขนาดของคอลเล็กชันผู้ได้รับรางวัลโนเบลของคุณกันเลย!
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Java เบื้องต้น
คำแนะนำการฝึกหัด
- แสดงผลความยาวของอาร์เรย์
literatureLaureatesและchemistryLaureates
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
class AllNobelLaureates {
public static void main(String[] args) {
String[] physicsLaureates = {"Curie", "Einstein", "Fermi"};
String[] literatureLaureates = {"Kipling", "Shaw", "Hemingway", "Seifert"};
String[] chemistryLaureates = {"Curie", "Heyrovsky"};
// Print the lengths of the arrays
System.out.println(physicsLaureates.length + " physics laureates");
System.out.println(literatureLaureates.____ + " literature laureates");
System.out.println(____ + " chemistry laureates");
}
}