字元
你拿到一份要列印在紙上的動詞清單,你想確認印表機裡的墨水是否足夠印出所有字元。
本練習屬於課程
Java 中級
練習說明
- 找出
conjugation陣列裡有多少個單字。 - 選擇正確的「比較」運算子,確保我們維持在
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");
}
}