Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Programming questions