시작하기무료로 시작하기

문자

인쇄할 동사 목록이 주어졌고, 프린터의 잉크가 모든 문자를 출력하기에 충분한지 확인하려고 해요.

이 연습은 강의의 일부입니다

중급 Java

강의 보기

연습 안내

  • conjugation Array에 몇 개의 단어가 있는지 찾으세요.
  • tabLength초과하지 않도록 올바른 비교 연산자를 선택하세요.
  • 각 반복이 끝날 때 i를 증가시키기 위한 적절한 갱신 연산자를 고르세요.
  • conjugation에서 각 word를 가져오도록 변수를 올바르게 작성하세요.

실습형 인터랙티브 연습

이 예제를 이 샘플 코드를 완성하여 풀어보세요.

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");
  }
}
코드 편집 및 실행