Question: Write a method called swapPairs that accepts an array of integers and swaps the elements at adjacent indexes. That is, elements 0 and 1 are
Write a method called swapPairs that accepts an array of integers and swaps the elements at adjacent indexes. That is, elements 0 and 1 are swapped, elements 2 and 3 are swapped, and so on. If the array has an odd length, the final element should be left unmodified. For example, the list [10, 20, 30, 40, 50] should become [20, 10, 40, 30, 50] after a call to your method.
Step by Step Solution
3.30 Rating (179 Votes )
There are 3 Steps involved in it
public static void ... View full answer
Get step-by-step solutions from verified subject matter experts
