開始使用免費開始

最大值

你需要在這份標籤清單中找出最長的單字,以決定你即將印出的視覺化中泡泡的大小。

本練習屬於課程

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));
  }
}
編輯並執行程式碼