title: Java: Three strings, lexicographic order
body: <p>beginner Java programmer here. I am trying to compare three strings to each other, and have the system spit out the second/middle word in lexicographic order. </p>
  
  <pre><code>import java.util.*;
  
  public class Ordered2
  {
  public static void main(String[] args)
  {
      String firstString, secondString, thirdString;
  
      Scanner keyboard = new Scanner(System.in);
  
      System.out.println("Enter three different strings.");
      System.out.println("The string in the middle order lexicographically will be displayed.");
      firstString = keyboard.nextLine();
      secondString = keyboard.nextLine();
      thirdString = keyboard.nextLine();
  
      String topString, middleString, bottomString;
  
      if (firstString.compareTo(secondString) &gt; 0 &amp;&amp; (firstString.compareTo(thirdString) &gt; 0)) 
      { topString = firstString; }
      else if (firstString.compareTo(secondString) &lt; 0 &amp;&amp; (firstString.compareTo(thirdString) &gt; 0)) {
      middleString = firstString; }
      else { bottomString = firstString; }
  
      if (secondString.compareTo(firstString) &gt; 0 &amp;&amp; (secondString.compareTo(thirdString) &gt; 0)) {
      topString = secondString; }
      else if (secondString.compareTo(firstString) &lt; 0 &amp;&amp; (secondString.compareTo(thirdString) &gt; 0)) {
      middleString = secondString; }
      else { bottomString = secondString; }
  
      if (thirdString.compareTo(secondString) &gt; 0 &amp;&amp; (thirdString.compareTo(firstString) &gt; 0)) {
      topString = thirdString; }
      else if (thirdString.compareTo(secondString) &lt; 0 &amp;&amp; (thirdString.compareTo(firstString) &gt; 0)) {
      middleString = thirdString; }
      else { bottomString = thirdString; }
  
      System.out.println("The second string in lexicographic order: " + middleString);
      }
  }
  </code></pre>
  
  <p>This does not compile, and tells me that middleString has not been initialized. Any help would be appreciated.</p>