// Helene Martin, CSE 142 // These methods demonstrate reference semantics for arrays. import java.util.*; public class ReverseArray { public static void main(String[] args) { int[] a = {3, 23, 43, 278, 15}; reverse(a); System.out.println(Arrays.toString(a)); } // given an array of integers, reverse its content public static void reverse(int[] a) { // need to stop halfway or we undo our work! // see jGRASP debugger for (int i = 0; i < a.length / 2; i++) { swap(a, i, a.length - 1 - i); } } // given an array of integers and two indexes, swap the values // at those two indexes public static void swap(int[] array, int i1, int i2) { int temp = array[i1]; array[i1] = array[i2]; array[i2] = temp; } }