JAVA

In this exercise, you are given a string and a word. You should return the index location of the SECOND instance of that word. If the word doesn’t exist twice, return -1.

Example:

findSecond("A very, very good day", "very") --> 8
findSecond("A very good day", "very") --> -1

Respuesta :

Answer:

Answer is, as always, in the attached screenshot!

Explanation:

In order to solve this we need to find the index of the string the first time, which will allow us to specify that as a new starting index to find the index of the second occurrence of the string. (Starting from +1 to get out of the string).

Really appreciate helping someone out with Java (it is my favourite programming language and I would say I know quite a bit about it).

Hope this helps!

Ver imagen rainestormee