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.
This exercise is part of the course
Intermediate Java
Exercise instructions
- 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
fromconjugation
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
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");
}
}