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

Answer:

Perhaps. Usually methods just indicate that an error has happened and let their caller decide on what error message to print.


Testing the Method

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("Test A:");
    operate.printRange( ar1, 0, 3);
    
    System.out.println("Test B:");
    operate.printRange( ar1, -1, 4);
    
    System.out.println("Test C:");
    operate.printRange( ar1, 1, 12);
  }

}      

The modified method needs to be tested. The main (above) does this. The program prints:

Test A:
-20 19 1
Test B:

Test C:
19 1 5 -1 27 19 5

In "Test A" the parameters are correct and the correct range of the array is printed.

In "Test B" the method is asked to start with an index of -1. The test in the for loop returns false right away, and the loop body is never executed.

In "Test C" the method is asked to print beyond the end of the array, but it quits after it has printed the last element.


QUESTION 16:

What will this call print out:

operate.printRange( ar1, 3, 3);