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](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/01/65b7cd034cae5_38765b7cd0320dba.jpg)
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
Get step-by-step solutions from verified subject matter experts
