Contenido del Curso
Java Extended
Java Extended
Challenge: Finding the Longest Word
Tarea
Write a program that finds the longest word in a string and outputs it along with the index of its first occurrence.
- The program should split the string into words and check the length of each word.
- For each word, compare its length with the length of the current longest word.
- If the current word is longer than the longest one, update the longest word and its index.
- Finally, output the result in the format:
"Longest word: [word] at index [index]"
, where[word]
is the longest word and[index]
is the index of its first occurrence in the string.
¡Gracias por tus comentarios!
Challenge: Finding the Longest Word
Tarea
Write a program that finds the longest word in a string and outputs it along with the index of its first occurrence.
- The program should split the string into words and check the length of each word.
- For each word, compare its length with the length of the current longest word.
- If the current word is longer than the longest one, update the longest word and its index.
- Finally, output the result in the format:
"Longest word: [word] at index [index]"
, where[word]
is the longest word and[index]
is the index of its first occurrence in the string.
¡Gracias por tus comentarios!
Challenge: Finding the Longest Word
Tarea
Write a program that finds the longest word in a string and outputs it along with the index of its first occurrence.
- The program should split the string into words and check the length of each word.
- For each word, compare its length with the length of the current longest word.
- If the current word is longer than the longest one, update the longest word and its index.
- Finally, output the result in the format:
"Longest word: [word] at index [index]"
, where[word]
is the longest word and[index]
is the index of its first occurrence in the string.
¡Gracias por tus comentarios!
Tarea
Write a program that finds the longest word in a string and outputs it along with the index of its first occurrence.
- The program should split the string into words and check the length of each word.
- For each word, compare its length with the length of the current longest word.
- If the current word is longer than the longest one, update the longest word and its index.
- Finally, output the result in the format:
"Longest word: [word] at index [index]"
, where[word]
is the longest word and[index]
is the index of its first occurrence in the string.