Using the Method

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page

Answer:

for ( int index=0; index <x.length; index++ )

  if ( x[index] > max )

    max = x[index] ;

Using the Method

Here is how our new method is used by a main() program. Notice that an ArrayOps object must be created before the method can be used.

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 defines a class called ArrayDemo.

  • ArrayDemo holds the static main() method.
  • main() creates an array object, ar1
  • main() creates an ArrayOps object, operate.
  • The findMax() method of the ArrayOps object is called with a reference to the array object ar1 as a parameter.

QUESTION 4:

What, exactly, is ar1 ?