/** * For question 2 on exam 2 for CS117, winter 2002. * * @author Jeff Ondich */ import javabook.*; class Swapper { public static void main( String[] args ) { int i = 1; int j = 2; swap( i, j ); System.out.println( i + ", " + j ); int[] intArray = new int[2]; intArray[0] = 3; intArray[1] = 4; arraySwap( intArray, 0, 1 ); System.out.println( intArray[0] + ", " + intArray[1] ); Thing thing1 = new Thing( 5 ); Thing thing2 = new Thing( 6 ); thingSwap( thing1, thing2 ); System.out.println( thing1.getValue() + ", " + thing2.getValue() ); } public static void swap( int a, int b ) { int temp = a; a = b; b = temp; } public static void arraySwap( int[] a, int i, int j ) { int temp = a[i]; a[i] = a[j]; a[j] = temp; } public static void thingSwap( Thing a, Thing b ) { Thing temp = a; a = b; b = temp; } }