title: Using command line args for completed hanoi program?
body: <p>I just finished my towers of hanoi program. It works flawless, except now I need to somehow make it so my program can read command line arguments (and produce the same results as in my program). My program performs the exact same tasks as the output below, I just don't know how to make them look like the example below since I have never used command line arguments.</p>
  
  <p>Frustrating for me, anyway, some example input should look like this :</p>
  
  <p><code>java hanoi 3 6</code> will solve the puzzle 4 times, for 3, 4, 5 and 6 disks, respectively.<br>
  <code>java hanoi 3 2</code> will solve the puzzle once, for 3 disks.<br>
  <code>java hanoi dog 6</code> will solve the puzzle 4 times, for 3, 4, 5 and 6 disks, respectively.</p>
  
  <p><strong>How do I convert my program to use command line args like this?</strong></p>
  
  <p>Code:</p>
  
  <pre><code>import java.util.Scanner;
  import java.util.*;
  
  public class hanoi {
      static int moves = 0;
      static boolean displayMoves = false;
  
      public static void main(String[] args) {
          System.out.print(" Enter the minimum number of Discs: ");
          Scanner minD = new Scanner(System.in);
        String height = minD.nextLine();
        System.out.println();
        char source = 'S', auxiliary = 'D', destination = 'A'; // 'Needles'
  
        System.out.print(" Enter the maximum number of Discs: ");
          Scanner maxD = new Scanner(System.in);
        int heightmx = maxD.nextInt();
  
  //       if (heightmx.isEmpty()) {   //If not empty
  //          // iMax = Integer.parseInt(heightmx);
  //          int iMax = 3;
  //          hanoi(iMax, source, destination, auxiliary);
  //       }  
        System.out.println();
  
  
        int iHeight = 3; // Default is 3 
        if (!height.trim().isEmpty()) { // If not empty
        iHeight = Integer.parseInt(height); // Use that value
  
        if (iHeight &gt; heightmx){
           hanoi(iHeight, source, destination, auxiliary);
        }
  
          System.out.print("Press 'v' or 'V' for a list of moves: ");
          Scanner show = new Scanner(System.in);
          String c = show.next();
          displayMoves = c.equalsIgnoreCase("v");   
        }
  
        for (int i = iHeight; i &lt;= heightmx; i++) {     
             hanoi(i,source, destination, auxiliary);
           System.out.println(" Total Moves : " + moves);                    
        }
      }
  
      static void hanoi(int height,char source, char destination, char auxiliary) {
          if (height &gt;= 1) {
              hanoi(height - 1, source, auxiliary, destination);
              if (displayMoves) {
                  System.out.println(" Move disc from needle " + source + " to "
                          + destination);
              }
              moves++;
              hanoi(height - 1, auxiliary, destination, source);
          } 
      }
  }
  </code></pre>