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
  public static 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 findMax() method is static, which means that it is part of the class, not part of any object. A static method can be invoked without needing an object. Look back to chapter 40 if you need to review this topic (which has not been used much until now.)

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

The parameter x means "whatever data is supplied when the method is invoked." This may be different for different runs.


QUESTION 3:

Fill in the blank so that the method is complete.


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