Use recursion to implement a method public static int indexOf(String text, String str) that returns the starting
Question:
Use recursion to implement a method
public static int indexOf(String text, String str)
that returns the starting position of the first substring of the text that matches str. Return –1 if str is not a substring of the text.
For example, s.indexOf("Mississippi", "sip") returns 6.
Hint: This is a bit trickier than Exercise E13.8, because you must keep track of how far the match is from the beginning of the text. Make that value a parameter variable of a helper method.
Data from Exercise E13.8
Use recursion to implement a method
public static boolean find(String text, String str)
that tests whether a given text contains a string. For example, find("Mississippi", "sip") returns true.
Hint: If the text starts with the string you want to match, then you are done. If not, consider the text that you obtain by removing the first character.
Step by Step Answer: