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

Answer:

The complete program follows:


Completed printRange()

class ArrayOps
{
  // other methods

  // print elements start through end
  public static void printRange ( int[] x, int start, int end )
  {
    for ( int index=start; index <= end ; index++ )
      System.out.print( x[index] + " " );
    System.out.println();
  }

}

public class ArrayDemo
{
  public static void main ( String[] args ) 
  {
    int[] ar1 =  { -20, 19, 1, 5, -1, 27, 19, 5 } ;
    
    // print elements at indexes 1, 2, 3, 4, 5
    ArrayOps.printRange( ar1, 1, 5 );
  }

}      

It is OK to use the same parameter names (like x) and the same local variable names (like index) in several methods. The scope of parameters and local variables is limited to the method in which they are declared.

When printRange() is called, the three actual values given in the call are copied to the parameters of printRange(). The parameter x refers to the array, start gets the value "1", end gets the value "5".


QUESTION 12:

What does this program print out?


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