字符
您拿到了一份需要打印到页面上的动词列表,想要确认打印机的墨水是否足够打印所有字符。
本练习是课程的一部分
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");
}
}