title: How to print the middle three characters of a String in Java?
body: <p>I am new to programming and working on a Java String assignment. The question says:</p>
  
  <ol>
  <li>Declare a variable of type String named middle3 (put your declaration with the other declarations near the top of the program) and use an assignment statement and thesubstring method to assign middle3 the substring consisting of the middle three characters of phrase (the character at the middle index together with the character to the left of that and the one to the right). Add a println statement to print out the result. Save, compile, and run to test what you have done so far.</li>
  </ol>
  
  <p>Here is what I have done:</p>
  
  <pre><code>String phrase = new String ("This is a String test.");
  String middle3 = new String ("tri"); //I want to print the middle 3 characters in "phrase" which I think is "tri".
  
  middle3 = phrase.substring (9, 11); // this only prints out 1 letter instead of 3
  
  
  System.out.println ("middle3: " + middle3);
  </code></pre>
  
  <p>Here is my output:</p>
  
  <pre><code>Original phrase: This is a String test.
  Length of the phrase: 18 characters
  middle3:  S
  </code></pre>
  
  <p>I also think that there are 18 characters in the string "phrase", but if there isn't, please let me know. Thank you in advance for all your help!</p>