Reverse the word order · Invertir el orden de las palabras
Reverse the word order
Given a sentence of space-separated words, return the words in reverse order: the quick brown → brown quick the. Split on spaces with s.split(" "), then build the result from the last word to the first. A StringBuilder is the tidy way to join them.
Invertir el orden de las palabras
Dada una oración con palabras separadas por espacios, devuelve las palabras en orden inverso: the quick brown → brown quick the. Separa las palabras usando s.split(" "), luego construye el resultado desde la última palabra hasta la primera. Un StringBuilder es la forma ordenada de unirlos.
Complete reverseWords(String s) so it returns the space-separated words in reverse order. Example: the quick brown becomes brown quick the. · Completa reverseWords(String s) para que devuelva las palabras separadas por espacios en orden inverso. Ejemplo: the quick brown se convierte en brown quick the.
Click Run to see the output here. · Haz clic en Ejecutar para ver la salida aquí.