exam1

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");
        System.out.println(example1);

        String example2 = reverseOdd("One two three four");
        System.out.println(example2);

        String example3 = reverseOdd("Make sure uoy only esrever sdrow of ddo length");
        System.out.println(example3);
    }

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

Comments

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