Question: Question 3 Complete the code in this function to find and return the lowest index in the String ar- ray stringArray that the String target

Question 3 Complete the code in this function to find and return the lowest index in the String ar- ray stringArray that the String target occurs. If the String target does not occur in stringArray, -1 should be returned. Starting code: public int indexoffirstOccurrence (String stringArray, String target] return -1; As an example of how this function should work, this code should print 1, because the word "Java" appears at index 1. String sentence - { "Learning", "Java", "is", "fun."|; int indexofWordJava - indexofFirstoccurrence (sentence, "Java") ; System. out. . print In (indexofWordJava) ; Hint: you cannot compare two Strings using the -- operator! This will be false unless the two Strings are actually the same String object, not just two Strings with the same letters. To check whether two Strings have the same letters, use the equals () method: if (myStringl . equals (mystring?))
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
