Hi, i posted the other day with practice questions i was getting stuck with and i am stuck again
Please firstly can i ask you dont post full solutions.
The question is from here
http://www.javabat.com/prob/p141494
and reads
Given a string and a second "word" string, we'll say that the word matches the string if it appears at the front of the string, except its first char does not need to match exactly. On a match, return the front of the string, or otherwise return the empty string. So, so with the string "hippo" the word "hi" returns "hi" and "xip" returns "hip". The word will be at least length 1.
startWord("hippo", "hi") → "hi" startWord("hippo", "xip") → "hip" startWord("hippo", "i") → "h"
I am getting very stuck, the wording of the question isn't helping me! This is the code i have so far
public String startWord(String str, String word)
{
if (str.startsWith(word)){
return str.substring(0, word.length());
}
if (str.substring(1, str.length()).equals(word.substring(1, word.length()))){
return str.substring(0, word.length());
}
return "";
}
hopefully someone will be able to help me out here with a pointer or 2, thank you for the help