logo CodeStepByStep logo

swapPairs

Language/Type: Java string return
Related Links:

Write a method named swapPairs that accepts a string as a parameter and returns a new string such that each pair of adjacent letters will be reversed. If the string has an odd number of letters, the last letter is unchanged. For example, if a string variable s stores "example", the call of swapPairs(s); should return "xemalpe". If s had been "hello there", the call would produce "ehll ohtree".

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.