Reverse the word order
This page needs a recent browser (with SharedArrayBuffer support). Please update Chrome, Edge, Firefox or Safari to the latest version.
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.
Complete reverseWords(String s) so it returns the space-separated words in reverse order. Example: the quick brown becomes brown quick the.
Click Run to see the output here.