Question: Description Loops 5 (SwapPairs) [REQUIRED] Write a method named swapPairs that accepts a String as a parameter and returns that String with each pair

Description Loops 5 (SwapPairs) [REQUIRED] Write a method named swapPairs that accepts

Description Loops 5 (SwapPairs) [REQUIRED] Write a method named swapPairs that accepts a String as a parameter and returns that String with each pair of adjacent letters reversed. If the String has an odd number of letters, the last letter is unchanged. For example, the call swapPairs("forget") should return "ofgrte" and the call swapPairs("hello there") should return "ehll ohtree". 234 LO SwapPairs.java 1 public class SwapPairs { public static void main(String[] args) { System.out.println(swapPairs("example")); System.out.println(swapPairs("hello there")); System.out.println(swapPairs("homework")); System.out.println(swapPairs("x")); System.out.println(swapPairs("")); 5 6 7 8 9 } 10 11 12 13 14 } 15 16 17 } public static void swapPairs(String swapPairs){ // Write the swapPairs method here

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!