title: Trying to display 3 random selected cities alphabetically
body: <p>Want to enter 3 cities in any order and want java to display them alphabetically. Thought about using the swap option but thought the enclosed code would work with an "if" "else" statement. Any ideas...Thanks</p>
  
  <pre><code>import java.util.Scanner;
  
  public class OrderTwoCities {
      public static void main(String[] args) {
      Scanner input = new Scanner(System.in);
  
      // Prompt the user to enter two cities
      System.out.print("Enter the first city: ");
      String city1 = input.nextLine();
      System.out.print("Enter the second city: ");
      String city2 = input.nextLine();
      System.out.print("Enter the third city: ");
      String city3 = input.nextLine();
  
      if (city1.compareTo(city2) &lt; 0 &amp;&amp; city2.compareTo(city3) &lt; 0)
          System.out.println("The cities in alphabetical order are " +
          city1 + " " + city2 + " " + city3);
      else
          System.out.println("The cities in alphabetical order are " +
          city3 + " " + city2 + " " + city1);
      }
  }
  </code></pre>