Bắt đầu ngayBắt đầu miễn phí

Characters

You have been given a list of verbs to print on a page, and you want to know if there's enough ink in your printer to print all the characters.

Bài tập này là một phần của khóa học

Intermediate Java

Xem khóa học

Hướng dẫn bài tập

  • Find how many words are in the conjugation Array.
  • Choose the proper comparison operator to make sure we stay below tabLength.
  • Select the appropriate updating operator to increase i at the end of each run.
  • Write down the variable to make sure that we get each word from conjugation.

Bài tập tương tác thực hành trực tiếp

Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.

class CharacterCounter {
  public static void main(String[] args) {
    String[] conjugation = {"hide", "hindered", "hiding", "hidden", "hindering", "hid", "hides", "hinder"};
    // Retrieve the number of words in the array by calling the correct field
    int tabLength = conjugation.____;
    int numberOfCharacters = 0;

    // Choose the appropriate operators (logical and increment)
    for (int i = 0; i ____ tabLength; i____) {
      // Give the proper variable to get each word out of conjugation
      String word = conjugation[____];
      numberOfCharacters += word.length();
    }
    System.out.println("There are " + numberOfCharacters + " characters in the list");
  }
}
Chỉnh sửa và Chạy Mã