3. Consider the following method, which returns the number of times the parameter String word
occurs in the parameter array wordArray:
public static int countOccurrences (String[] wordArray, String word) {
int result;
result = 0;
for (int i = 0; i < wordArray.length; i++) {
if (wordArray[i] == word) {
result = result + 1;
return result;
Unfortunately, the above method contains a bug. This bug causes the method to return 0 instead of
the expected value of 2 when it is called in the following code fragment:
String[] animalism = {
new String ("four"),
new String ("legs"),
new String ("good"),
new String ("two"),
new String ("legs"),
new String ("bad")
};
int count = count Occurrences (animalism, "legs");
System.out.println("Number of occurrences: " + count);
Describe what the problem is, and suggest a simple way to fix it. BE BRIEF; overly long answers
will be grounds for mark deductions.