Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * this one is lisa's solution with a small change
- */
- public String wordEnds(String str, String word) {
- StringBuffer out = new StringBuffer ();
- int s_l = str.length(), w_l = word.length();
- for (int i = 0; i < s_l-w_l+1; i++) {
- if (str.startsWith(word, i)) {
- if (i > 0) out.append(str.charAt(i-1));
- if (i+w_l < s_l) out.append(str.charAt(i+w_l));
- }
- }
- return out.toString();
- }
Add Comment
Please, Sign In to add comment