Začněte nyníZačněte zdarma

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

Zobrazit kurz

Pokyny k cvičení

  • Zjisti, kolik slov obsahuje pole conjugation.
  • Zvol správný operátor porovnání, aby hodnota i zůstala pod tabLength.
  • Vyber vhodný operátor aktualizace pro zvyšování hodnoty i na konci každého průchodu.
  • Doplň proměnnou tak, abychom z pole conjugation postupně získali každé slovo word.

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");
  }
}
Upravit a spustit kód