Question: java Write a method Pairswap that takes an array of integers as a parameter and do pair swapping for the adjacent elements only if they
Write a method "Pairswap" that takes an array of integers as a parameter and do pair swapping for the adjacent elements only if they are not in order (the value of the element in the lower index is greater than value of the element in the higher index). It returns the swapped array of integers. For each index i, the method has to compare element in index with element in index i+1. For example, if "arrl" has 6 indices, "PairSwap" will check the index pairs 0-1, then 1-2, then 2-3, 3-4, and 4-5, and do pair swapping only if the elements are out of order In your main class create an array of integers "arrl" and prompt the user to enter the values of the array. Print the original array. Implement Pairswap (arri). Print the swapped array. Sample run: The original array is [2, 7, 1, 8, 4, 6, 31 The swapped array is 12, 1, 7, 4, 6, 3, B]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
