for ( int index=0; index <x.length; index++ )
if ( x[index] > max )
max = x[index] ;
class ArrayDemo { public static void main ( String[] args ) { int[] ar1 = { -20, 19, 1, 5, -1, 27, 19, 5 } ; ArrayOps operate = new ArrayOps(); // create an ArrayOps object int biggest = operate.findMax( ar1 ); // call findMax() with a reference to the array System.out.println("The maximum is: " + biggest ); } }
The program demonstrates the ArrayOps
class.
ArrayDemo
. ArrayDemo
holds the static main()
method.main()
creates an array object referenced by ar1
main()
creates an ArrayOps
object referenced by operate
.ArrayOps
object must be created before its method can be used.findMax()
method of the ArrayOps
object is called
with a reference to the array object as an actual parameter.
What, exactly, is ar1
?