// Helene Martin, CSE 142 // Demonstates reference semantics -- the reverse method // doesn't need to return anything. import java.util.*; public class Reverse { public static void main(String[] args) { int[] values = {54, 23, 12, -11, 45, 555}; System.out.println(Arrays.toString(values)); // Because of reference semantics, the array // is reversed by this method. reverse(values); System.out.println(Arrays.toString(values)); } // reverse the contents of the array // first swap value at 0 with value at length - 1 // then value at 1 with value at length - 2 // Reverses the content of the specified array public static void reverse(int[] values) { for (int i = 0; i < values.length / 2; i++) { int temp = values[i]; values[i] = values[values.length - 1 - i]; values[values.length - 1 - i] = temp; } } }