Znaky
Máš k dispozici seznam sloves, která chceš vytisknout, a potřebuješ zjistit, jestli máš v tiskárně dost inkoustu na všechny znaky.
Toto cvičení je součástí kurzu
Intermediate Java
Pokyny k cvičení
- Zjisti, kolik slov obsahuje pole
conjugation. - Zvol správný operátor porovnání, aby hodnota
izůstala podtabLength. - Vyber vhodný operátor aktualizace pro zvyšování hodnoty
ina konci každého průchodu. - Doplň proměnnou tak, abychom z pole
conjugationpostupně získali každé slovoword.
Interaktivní cvičení na vyzkoušení si v praxi
Vyzkoušejte si toto cvičení dokončením tohoto ukázkového kódu.
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");
}
}