Question: Four integers are read from input and stored into the array arrayToModify. Write a static method swapArrayPos ( ) that takes an integer array parameter
Four integers are read from input and stored into the array arrayToModify. Write a static method swapArrayPos that takes an integer array parameter and swaps the secondtolast element with the last element of the array.
Ex: If the input is then the output is:
Original array: Changed array:
import java.util.Scanner;
public class ArrayParameterReferences
Your code goes here
public static void printArrint arr
int i;
for i ; i arr.length; i
System.out.printarri;
System.out.println;
public static void mainString args
Scanner scnr new ScannerSystemin;
final int NUMELEM ;
int arrayToModify new intNUMELEM;
int i;
int userNum;
for i ; i arrayToModify.length; i
arrayToModifyi scnrnextInt;
System.out.printOriginal array: ;
printArrarrayToModify;
swapArrayPosarrayToModify;
System.out.printChanged array: ;
printArrarrayToModify;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
