Guest User

Untitled

a guest
Sep 25th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. /*
  2. * this one is lisa's solution with a small change
  3. */
  4. public String wordEnds(String str, String word) {
  5. StringBuffer out = new StringBuffer ();
  6. int s_l = str.length(), w_l = word.length();
  7. for (int i = 0; i < s_l-w_l+1; i++) {
  8. if (str.startsWith(word, i)) {
  9. if (i > 0) out.append(str.charAt(i-1));
  10. if (i+w_l < s_l) out.append(str.charAt(i+w_l));
  11. }
  12. }
  13. return out.toString();
  14. }
Add Comment
Please, Sign In to add comment