I am not good at Java so I just would like to say in advance “THIS IS MY HOMEWORK” and please “DO NOT DO MY HOMEWORK”, this is the very first homework on recursion so this is my first time. Having said that, these are the instructions of my homework but I am not sure the steps that I need to take in order to achieve the goal. All I need is a great guy/girl who can give me good details on how to finish my homework, kind of steps. I have read the book, checked some websites about recursion, but I feel that I need a little more help.
Write a recursive static method that, given two string s and t,
returns an array of all positions where t occurs in s. For example,
findLocations(“Frances ran and ran”, “ran”) returns [1, 8, 16].
I would probably approach it like this:
Given the argumets
inputStringandsubstring, callindex = inputString.indexOf(substring).If the
substringis not found (index= -1), you should return the empty array (new int[0]), since no occurrences of the substring exists in theinputString.Otherwise the
substringdoes exist, in which case you should do the following:Get the array of indexes for the remaining part of the string, using something like
arr = findLocations(inputString.substring(index+1), substring)Adjust the indexes in
arrby addingindexto each element.return
index, concatenated witharr.