operate.printRange( ar1, 3, 3);

Answer:

This will print out element 3 of the array, the value 5.

Sum Method

Here is the ArrayOps class, now including with a new method. This new method adds up all the elements in an array.

class ArrayOps
{
  // . . . previous methods go here

  // add up all the elements in an array
  int sumElements ( int[] nums )
  {
    int sum = ;

    for ( int   ;  ;   )

       ;

    return   ;
  }

}

Here is how the method might be used in main():

class ArrayDemo
{
  public static void main ( String[] args ) 
  {
    ArrayOps operate = new ArrayOps();
    int[] ar1 =  { -20, 19, 1, 5, -1, 27, 19, 5 } ;
 
    System.out.println("The sum of elements is: " + 
      operate.sumElements( ar1 ) );   
  }

}

The declaration of the method says that it expects an array of int as a parameter, and that it will return an int back to the caller when it is done:

int sumElements ( int[] nums )

QUESTION 15:

Fill in the blanks of the sumElements() method.