A good answer might be:

A parameter is data that is supplied to a method just before it starts running.


Array used as a Parameter

Here is a (nearly complete) program:

import java.io.*;

class ArrayOps
{                         // the parameter x refers to the data
  void print( int[] x )   //  this method is called with.                     
  {
    for ( int ____________; _________________; ____________ )
      System.out.print( x[index] + " " );
    System.out.println();
  }
}

class ArrayDemo
{
  public static void main ( String[] args ) 
  {
    ArrayOps operate = new ArrayOps(); // create an ArrayOps object
    int[] ar1 =  { -20, 19, 1, 5, -1, 27, 19, 5 } ;

    System.out.print  ("\nThe array is: " );
    operate.print( ar1 );   // call the print() method of the object
  }

}      
  1. The program defines a class called ArrayOps.
    • ArrayOps contains a method print() to print out each element of an array.
    • The parameter list is: int[] x
      • This declares a formal parameter x which will be a reference to an array object.
      • The caller is expected to supply a reference to an array as an actual parameter

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

QUESTION 2:

Fill in the blanks so that the method prints out each array element.