Personajes
Te han dado una lista de verbos para imprimir en una página, y quieres saber si hay suficiente tinta en tu impresora para imprimir todos los caracteres.
Este ejercicio forma parte del curso
Java intermedio
Instrucciones del ejercicio
- Averigua cuántas palabras hay en el arreglo
conjugation
. - Elige el operador de comparación adecuado para asegurarte de que nos mantenemos por debajo de
tabLength
. - Selecciona el operador de actualización adecuado para aumentar
i
al final de cada ejecución. - Escribe la variable para asegurarnos de que obtenemos cada
word
deconjugation
.
Ejercicio interactivo práctico
Prueba este ejercicio completando el código de muestra.
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");
}
}