Alex,
That won't completely eliminate the exceptions found. we still have the problem of
testing the neighbors of [0,0] and trying for [-1,0] - we're out of bounds.
you might be able to write two methods, something like
then, inside your main loops, you'd do:
in other words, for any given element, you only test the row ABOVE it if you are in row 1 or greater. you only test the row BELOW it if you are at 9 or less (otherwise those rows don't exist, and you'd get your outof bounds exception). you ALWAYS test the row your element is IN.
so now that we know which rows to test, what do we do with them? well, there are two kinds of rows - the one our 'center' element is in that we DON'T want to test, and rows where we want to test all three elements. that's why i made the two methods.
writing the "sameRow" method, we only test to the left if y > 0, and only to the right if y < 9.
now we write the "differentRow" method. AHA!!! we need to test the elements to the left and right - we've already got code for that!!! so i call that method, then test the center one.
i'm not sure how your counting the total number of hits. these methods may return ints for a sum of the total number of hits, or you may just want them to return booleans if you only care if there is "one or more" hits in the 8 neighbors.
so, have i TOTALLY confused you now?
;-)