X34: wordEnds

Write a function in Java that implements the following logic: Given a string str and a non-empty word, return a string made of each character just before and just after every appearance of the word in str. Ignore cases where there is no character before or after the word, and a character may be included twice if it is between two words.

Examples:

wordEnds("abcXY123XYijk", "XY") -> "c13i"
wordEnds("XY123XY", "XY") -> "13"
wordEnds("XY1XY", "XY") -> "11"

Your Answer:

Reset

Feedback

Your feedback will appear here when you check your answer.