Complete the following assignments from the textbook:
public class Homework4A
{
public static int[] findLocations(String s, String t)
{
ArrayList<Integer> ans = new ArrayList<Integer>();
findLocationsHelper(s, t, 0, ans);
int[] pos = new int[ans.size()];
for(int i = 0; i < ans.size(); i++) pos[i] = ans.get(i);
return pos;
}
public static void findLocationsHelper(String s, String t, int start, ArrayList<Integer> ans)
{
if (start < s.length() - 1)
{
int pos = s.indexOf(t, start);
if (!ans.contains(pos))
ans.add(s.indexOf(t,start));
findLocationsHelper(s, t, start, ans);
start++;
}
}
}
There is one obvious mistake, one subtle one. In a file problem7.txt,
provide (a) a description of each mistake (b) for each mistake, a trace
with an example of your choice that demonstrates the mistake (c) a
description how to fix the mistakes (d) a trace of the run
findLocationsHelper("mississippi", "i", 0, ans).
Puzzle p = new Puzzle("123","4X6","789");
boolean b = p.isSolved();
Write down the sequence of line numbers that are executed in the
isSolved method.