Question
Asked by:
$15.00 Recursive string problem needed as Java code(I attached here file with a partial solution i managed to complete so far )
- From Computer-Science: Object-Oriented-Programming , Computer-Science: General-CS
- Closed, but you can still post tutorials
- Due on Jan. 25, 2009
- Asked on Jan. 24, 2009 at 06:57:44AM
Q:The following program MUST be ONLY recursive without any loops using at all anywhere in it..its possible using 4 string functions which i wrote after the question
Q)Write a static recursive function called maximal that is:
public static int maximal (String st1,String st2) which gets 2 strings st1,st2 and returns the length of the longest sub-string containing the chars(in any order in a row) of st1 in st2.
for example:if st1 is xyz and s2 is abxyryxzycx,the function returns 4 since is the longest combination of st1 chars in s2...(the shorter combinations were:xy and x)...
*)public char charAt(int i)-returning char located at i index.
*)public int indexOf (int ch)-returning index of the ch char,if no char at all its -1.
*)public int length()-returning the length of string
*)public String substring(int i)- returning the substring starting from the i index till the end of the string.
Thank you.
Another clarification making things easier to understand..
The charAt returns the char of i index in the related string ,and the use of it will be mostly like..
char firstChar = str.charAt(0); (puts first index char into firstChar)
Attachments:
solution.txt (0K)
To which TAboy26 said: you are right that st1 has just 3 chars but even if its chars appear in a row like xyxyxzxyxx it will be 10 max length.. so here in st2 yxzy is 4 length (before it theres r and after it c which spoil the row).. thanx



