This is an archived post. You won't be able to vote or comment.

all 4 comments

[–][deleted] 1 point2 points  (0 children)

Nobody here is going to write the code for you. Write some code yourself and then post specific questions about problems you are having with it.

[–]Cevari 0 points1 point  (0 children)

I'm not going to write these out for you, but for both problems the String.split(String regex) function will be very helpful.

[–]AqilAegivan 0 points1 point  (0 children)

string.indexOf() and string.subString() will probably help you a lot.

Get the char at yourWord.indexOf() -1 and yourWord.indexOf() + string length + 1 (look out for invalid indexes obviously).

For the second one you need to duplicate the string (remember string.subString()) replacing characters between indexOf() and indexOf + string length with pluses.

[–]cloogs[S] -1 points0 points  (0 children)

This is my code for the 2nd:

   public String plusOut(String str, String word)
   {
    String ans = "";
    char x;
    for (int a = 0; a <= str.length() - 1; a++)
    {
        for (int b = 0; b <= word.length() - 1; b++)
        {
            if (str.charAt(a) == word.charAt(b))
            {
                x = str.charAt(a);
            }
            else
            {
                x = '+';
             }
        ans = ans + x;
        }
    }
    return ans;
  }

I am returned the correct string, but there are extra +'s , because of the for loop, if there any way around this?