Loading...
Loading...
Loading...
A notice board app shows announcements word by word from the end. Read a sentence and print its words in reverse order, separated by single spaces. The letters inside each word stay in order. Extra spaces in the input are dropped.
Example 1
Input
Java is fun
Output
fun is Java
Example 2
Input
the sky is blue
Output
blue is sky the
Leading, trailing and repeated spaces disappear.
Try the problem first. Open one hint at a time.
Get the words with trim() and split("\\s+").
Loop over the array from the last index to 0 and append each word to a StringBuilder.
Add a space before every word except the first one you append.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor