Java > String-1 > makeOutWord (CodingBat Solution)


Given an "out" string length 4, such as "<<>>", and a word, return a new string where the word is in the middle of the out string, e.g. "<>". Note: use str.substring(i, j) to extract the String starting at index i and going up to but not including index j.

makeOutWord("<<>>", "Yay") → "<>"
makeOutWord("<<>>", "WooHoo") → "<>"
makeOutWord("[[]]", "word") → "[[word]]"


public String makeOutWord(String out, String word) {
  return out.substring(0,2) + word + out.substring(2,4);

1 comment :

  1. public String makeOutWord(String out, String word) {
    return "" + out.charAt(0) + out.charAt(1)
    + word + out.charAt(2) + out.charAt(3);


Follow Me

If you like our content, feel free to follow me to stay updated.


Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?


Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact