go to previous page   go to home page   go to next page

Answer:

By scanning through the elements of the array, updating a provisional maximum until all elements have been examined. This is the algorithm used in the previous chapter.


ArrayOps Class

class ArrayOps
{                          // the parameter x refers to the data
  int findMax( int[] x )   // this method is called with.                     
  {
    int max = x[0];

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

      if ( x[index]  )

        max = x[index] ;

    return max ;
  }
}

The program shows a partial definition of the ArrayOps class. The ArrayOps class contains a method findMax() that finds the maximum of an array.

The parameter list is of the method is: int[] x

The parameter x means "whatever data is supplied each time the method is run." This may be different for different runs.


QUESTION 3:

Fill in the blank so that the method is complete.