Answer:
-
array[ j ] = target- NO! a horrible bug!
This copies the reference contained in
targetinto cell j of the array
- NO! a horrible bug!
This copies the reference contained in
-
array[ j ] == target - NO! a less horrible bug! This tests if the two references are identical (it test there is one object that they both refer to.)
-
array[ j ].equals( target ) - Yes!
This checks if the two
Stringobjects contain the same characters.
Return when Found
Unless you enjoy late nights debugging programs that have no hope of ever running, look over those three answers. Two of them (the wrong ones) are very common bugs. They will happen to you. Learn to recognize them.
The program below has more of the search method.
Inspect the second if statement.
It is written so that if the target has just been found the
method immediately returns to the caller
with the index of the cell in which target was found.
The second return statement is NOT part of the loop body.
It is executed only when every cell of the array has been inspected
and the target has not been found.
QUESTION 19:
You know what to do with those blanks.