// ArrayMethods.java (c) 2004 Kari Laitinen // www.naturalprogramming.com // This program demonstrates the methods of the standard // class Arrays. // 2004-10-07 File created. // 2004-10-07 Last modification. import java.util.* ; class ArrayMethods { static void print_array( int[] given_array_of_integers ) { System.out.print( "\n\n " ) ; for ( int integer_index = 0 ; integer_index < given_array_of_integers.length ; integer_index ++ ) { System.out.printf( "%5d", given_array_of_integers[ integer_index ] ) ; } } public static void main( String[] not_in_use ) { int[] array_of_integers = { 44, 2, 53, 1, 32, 17, 53, 6 } ; /***** System.out.print( "\n Value 32 has index: " + Array.IndexOf( array_of_integers, 32 ) ) ; System.out.print( "\n Value 99 has index: " + Array.IndexOf( array_of_integers, 99 ) ) ; System.out.print( "\n Last value 53 has index: " + Array.LastIndexOf( array_of_integers, 53 ) ) ; *****/ print_array( array_of_integers ) ; /***** int[] original_array = (int[]) array_of_integers.Clone() ; print_array( original_array ) ; Array.Reverse( array_of_integers ) ; print_array( array_of_integers ) ; *****/ Arrays.sort( array_of_integers ) ; print_array( array_of_integers ) ; Arrays.fill( array_of_integers, 4, 7, 0 ) ; print_array( array_of_integers ) ; /**** Array.Copy( original_array, 0, array_of_integers, 4, 3 ) ; print_array( array_of_integers ) ; char[] array_of_characters = { 'z', 'X', '3', 'a', 'k', '=', '+' } ; print_array( array_of_characters ) ; Array.Sort( array_of_characters ) ; print_array( array_of_characters ) ; *******/ } }