Can anyone know how to do this Javabat plusout problem. I am not allowed to use Startwith code.
String where all chars have been replaced by pluses ("+"), except for appearances of the word string which are preserved unchanged.
plusOut("12xy34", "xy") → "++xy++"
plusOut("12xy34", "1") → "1+++++"
plusOut("12xy34xyabcxy", "xy") → "++xy++xy+++xy"
I work hard but fail to get all right.
public String plusOut(String str, String word)
{
String result="";
for(int i=0; i<str.length()-word.length()+1; i++)
if(str.substring(i,i+word.length()).equals(word))
{
result += word;
i++;
}
else
{
result += "++" ;
i++;
}
return result;
}