Perhaps. Usually "tools" merely indicate that an error has happened and let their caller decide on what error message to print.
The modified method needs to be tested.
Here is the testing class with several calls to printRange():
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 program prints:
Test A: -20 19 1 Test B: Test C: 19 1 5 -1 27 19 5
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.
What will this call print out:
operate.printRange( ar1, 3, 3);