logo CodeStepByStep logo

switchPairs

Language/Type: Java string return
Related Links:

Write a method named switchPairs that accepts a string as a parameter and returns that string with each pair of neighboring letters reversed. If the string has an odd number of letters, the last letter should not be modified. For example, the call switchPairs("example") should return "xemalpe" and the call switchPairs("hello there") should return "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.