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
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 Solution
3.43 Rating (162 Votes )
There are 3 Steps involved in it
class HelloWorld pu... View full answer
Get step-by-step solutions from verified subject matter experts
Document Format (2 attachments)
2106_61d6ac3467235_873092.pdf
180 KBs PDF File
2106_61d6ac3467235_873092.docx
120 KBs Word File
