ค่าสูงสุด
ต้องหาคำที่ยาวที่สุดในรายการป้ายกำกับนั้น เพื่อกำหนดขนาดของฟองในภาพที่จะแสดงผล
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Java ระดับกลาง
คำแนะนำการฝึกหัด
- กำหนดชนิดข้อมูลที่เหมาะสมให้
wordsList - ใส่การ เปรียบเทียบ ที่ถูกต้องเพื่อเลือกคำที่ ยาวกว่า
- ใส่ เมธอด ที่ถูกต้องเพื่อค้นหาคำที่ยาวที่สุด
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
class LongestFinder {
// Give the appropriate type to wordsList
static String findLongestIn(____ wordsList) {
String longest = "";
for (String word : wordsList) {
// Enter the fitting comparison to select the longer word
if (____)
longest = word;
}
return longest;
}
public static void main(String[] args) {
String[] words = {"possible", "first", "null", "avoidance", "mineral", "pretty", "tree", "rather", "innocuous"};
// Call the correct method to find the longest word
System.out.println(____(words));
}
}