Given an array arr, of type int , along with two int variables i and j, write some code that swaps the values of arr[i] and arr[j]. Declare any additional variables as necessary.

Given an array arr, of type int , along with two int variables i and j, write some code that swaps the values of arr[i] and arr[j]. Declare any additional variables as necessary.

LANGUAGE: JAVA

CHALLENGE:

Given an array arr, of type int , along with two int variables i and j, write some code that swaps the values of arr[i] and arr[j]. Declare any additional variables as necessary.

SOLUTION:

int temp = 0;
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;

Add comment