Yes. New lines are inserted into the program to show this:
In the revised program, the print() method is used
first with one array, and then with the other array.
This is possible because the parameter x of the method
refers to the current array,
whichever one is used in the method "call."
import java.io.*;
class ArrayOps
{
void print( int[] x )
{
for ( int index=0; index < x.length; index++ )
System.out.print( x[index] + " " );
System.out.println();
}
}
class ArrayDemo
{
public static void main ( String[] args )
{
ArrayOps operate = new ArrayOps();
int[] ar1 = { -20, 19, 1, 5, -1, 27, 19, 5 } ;
int[] ar2 = { 2, 4, 1, 2, 6, 3, 6, 9 } ;
System.out.print ("\nThe array is: " );
operate.print( ar1 ); // method call with the 1st array
System.out.print ("\nThe second array is: " );
operate.print( ar2 ); // method call with the 2nd array
}
}
The program will print the following:
C:\>java ArrayDemo The array is:-20 19 1 5 -1 27 19 5 The second array is: 2 4 1 2 6 3 6 9