Question: JAVA .....Write a method swapArrayEnds() that swaps the first and last elements of its array parameter. Ex: sortArray = {10, 20, 30, 40} becomes {40,
JAVA .....Write a method swapArrayEnds() that swaps the first and last elements of its array parameter. Ex: sortArray = {10, 20, 30, 40} becomes {40, 20, 30, 10}. The array's size may differ from 4. ...CODE :
import java.util.Scanner;
public class ModifyArray {
/* Your solution goes here */
public static void main (String [] args) { int numElem = 4; int[] sortArray = new int[numElem]; int i;
sortArray[0] = 10; sortArray[1] = 20; sortArray[2] = 30; sortArray[3] = 40;
swapArrayEnds(sortArray, numElem);
for (i = 0; i < numElem; ++i) { System.out.print(sortArray[i]); System.out.print(" "); } System.out.println(""); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
