The change to the program introduces an off-by-one error. The array index does not go far enough to test the last cell of the array.
With a ten-element initializer list, the above buggy program will fail about one time in ten (assuming random lists of data). Failure might not be obvious, because the answer it computes is close to the maximum. With a ten thousand element array, the program will fail about one time in ten thousand! Sloppy testing will never find this bug. Off-by-one errors can be very subtle.
Classic Bug (3): Not testing the "boundaries". Bugs are often found at the boundaries: at the beginning and ends of loops, at the beginning and ends of data, with large or small values (or zero), with a very large amount of data, or with no data at all (which should not break the program).
What happens when the following code is run?
int[] myWeeklyPay = {769, 588, 1245, 309, 388, 902}; int sum = 0; for ( int j=0; j<=6; j++ ) sum += myWeeklyPay[j];