// LargestWithArrayOutput.java Copyright (c) 2005 Kari Laitinen // http://www.naturalprogramming.com // 2005-03-27 File created. // 2005-03-27 Last modification. // This program works in the same way as LargestWithReturn.java. // In this version an array whose length is 1 is used to transfer // an int value from the called method to the caller. // This is not necessarily a nice way to use arrays. // The purpose of this program is to show how arrays behave as // method parameters. class LargestWithArrayOutput { static void search_largest_integer( int[] array_of_integers, int number_of_integers_in_array, int[] largest_integer_to_caller ) { int largest_integer = array_of_integers[ 0 ] ; int integer_index = 1 ; while ( integer_index < number_of_integers_in_array ) { if ( array_of_integers[ integer_index ] > largest_integer ) { largest_integer = array_of_integers[ integer_index ] ; } integer_index ++ ; } largest_integer_to_caller[ 0 ] = largest_integer ; } public static void main( String[] not_in_use ) { int[] first_array = { 44, 2, 66, 33, 9 } ; int[] second_array = { 888, 777, 66, 999, 998, 997 } ; int[] found_largest_integer = new int[ 1 ] ; search_largest_integer( first_array, 5, found_largest_integer ) ; System.out.print( "\n The largest integer in first_array is " + found_largest_integer[ 0 ] + ".\n" ) ; search_largest_integer( second_array, 6, found_largest_integer ) ; System.out.print( "\n The largest integer in second_array is " + found_largest_integer[ 0 ] + ".\n" ) ; } }