an anonymous user · September 23, 2022
 * Reverse the Odd Length Words
 * Given a string, reverse all the words which have odd length. The even length words are not changed.
 * Examples
 * reverseOdd("Bananas") ➞ "sananaB"
 * reverseOdd("One two three four") ➞ "enO owt eerht four"
 * reverseOdd("Make sure uoy only esrever sdrow of ddo length")
 * "Make sure you only reverse words of odd length"
 * Notes
 * There is exactly one space between each word and no punctuation is used.

public class Main {
    public static void main(String[] args) {
        String example1 = reverseOdd("Bananas");

        String example2 = reverseOdd("One two three four");

        String example3 = reverseOdd("Make sure uoy only esrever sdrow of ddo length");

    public static String reverseOdd(String str) {
        StringBuilder sb = new StringBuilder(reverseOdd);
        String reverseOdd = sb.reverse();
        return reverseOdd;
(Run the program to view its output)


Please sign up or log in to contribute to the discussion.