import java.util.*; public class ReverseArray { public static void main(String[] args) { int a = 12; int b = 15; // this method has no effect on a and be because // ints use value semantics (copied into parameters) swap(a, b); System.out.println(a + " " + b); int[] nums = {12, 43, 65, 76, 38, 65}; // this method reverses the array because // arrays are objects so are passed to methods // using reference semantics reverse(nums); System.out.println(Arrays.toString(nums)); } // swaps the values of two variables // because of value semantics, only affects the local variables public static void swap(int a, int b) { int temp = a; a = b; b = temp; } // reverses the order of values in an array public static void reverse(int[] nums) { // need to stop at half or we un-reverse for (int i = 0; i < nums.length / 2; i++) { int temp = nums[i]; nums[i] = nums[nums.length - 1 - i]; nums[nums.length - 1 - i] = temp; } } }