始める無料で始める

最大値

これから印刷するビジュアルでバブルの大きさを決めるため、ラベル一覧の中で最も長い単語を見つける必要があります。

この演習はコースの一部です

中級 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));
  }
}
コードを編集して実行