# JavaBat Solution String 1 makeOutWord

Codingbat solution to “makeOutWord”. This problem is found in the section String 1, and rest assured that Codingbat answers String 1 section provides a great introductory view into the world of String manipulation. Strings are Java’s key programming concept, and they enable Java programmers to do lot of interesting things; however, rest assured that manipulating Java Strings is no easy task. To further the problems that can be caused by Java’s strings, realize that string manipulation and concatenation is not something that is consistently taught through any college or introductory high school Computer Science courses.

String manipulation by Java programmers is something that is learned on your own. This is one of the things that makes string manipulation difficult. However, once Java programmer have mastered Java’s string manipulation abilities, they’ll be considered master’s of an art form. Indeed, manipulating Java strings is an art form.

Codingbat provides solution to the problem of learning the art form of Java String manipulation, by allowing beginner programmers to learn basic String manipulation syntax and programmer concepts on their own, and in an easy to understand manner. In short, Codingbat helps beginner programmers solve string manipulation problems such as CodingBat’s String 1 section. A Codingbat problem in this section is makeOutWord.

Here’s what Codingbat’s String 1 makeOutWord’s coding request wants us to answer:
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]]”

The following fully solved explanation to Codingbat Solution String 1 makeOutWord is provided to serve as a learning tool in the solving of Codingbat programming exercises:

/*First, Codingbat makeOutWord requires that you, the eager CodingBat solution finder, develop a method using Java’s awesome String class. Then, you define a parameter with the keyword String and this looks like “String out” and “String word”. These parameters are the method’s signature. Thus, the first part of your Codingbat answer to makeOutWord will have the following Java programming syntax:*/

``` public String makeOutWord(String out, String word) { ```
/*Note that when you have the String() class without a method signature, or set of parameters, what you are doing is that you are initializing a newly created String object so that it represents an empty character sequence.

Codingbat makeOutWord requires that we provide a signature to the method, so that it can return a value. makeOutWord uses the following Codingbat answer “String out” and “String word”, and this tells Codingbat’s method that it must return string values that will be represented using the words “out”, and “word.”

Once again, Codingbat answers our quest to develop great programming skills by a simple use of Java programming keywords. makeOutWord’s method summary requires that answer it with the Java keyword public. This keyword simply means that it is an access control modifier meaning that it is visible to all classes defined in its respective package, and that it can be accessed from outside the class that it was declared in. As such, the keyword public also means that it is applicable to a class, a method or a field.

Let’s continue with our solution to Codingbat String 1 makeOutWord */

/*The value required by Codingbat makeOutWord’s method is an interesting use of Java’s string manipulation abilities because it uses an interesting method found in Java String class. This method is called the substring method. The substring method has the following Java parameters (int beginIndex, and intEndIndex). These parameters are critical for this Codingbat answer in String 1 to compile correctly.

makeOutWord requires its Codingbat solution to use the substring method, and the length method in its return call.
However, you will invoke the original value of the String to form an interesting Codingbat solution. The method’s invocation will look like this “out.substring.”

Codingbat answer to makeOutWord gives us a value of 4 for our CodingBat Solution, and we must return a word within this coding prompt. Thus, the Codingbat solution will require the use of the substring method invoked with the word out, and the method’s signature will use intBeginIndex, and intEndIndex to return a correct response. These methods work by returning a new string that is a substring of this original string. The substring starts at the specified beginIndex, here it is 0, and extends to the character at index endIndex – 1, and here it is 2. Thus the length of the substring is endIndex-beginIndex.

Codingbat makeOutWord solution uses the intBeginIndex of 0, and 2, and it uses the intEndIndex of 2, and 4 to answer the coding prompt.

Codingbat String 1 makeOutWord solution:
*/

``` ```

``` return out.substring(0, 2) + word + out.substring(2, 4); } } ```

The fully solved Codingbat Answer to makeOutWord in String 1 section of Codingbat looks like this:
``` public String makeOutWord(String out, String word) { return out.substring(0, 2) + word + out.substring(2, 4); }```

Codingbat String 1 MakeOutWord