A parameter is data that is supplied to a method just before it starts running.
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
}
}
ArrayOps.
ArrayOps contains a method print() to print
out each element of an array.int[] x
x which will be a
reference to an array object.ArrayDemo.
ArrayDemo holds the static main() method.main() creates an ArrayOps object, operate.main() creates an array object, ar1 print() method of the ArrayOps object is called
with a reference to the array object ar1 as a parameter.