title: How to call recursion with Tower of Hanoi
body: <p>I'm trying to resolve Tower of Hanoi problem; I wrote this code:</p>
  
  <pre><code>public class TowersOfHanoi {
     public static void main(String[] args) {
        move(5, 1, 3);
        }
  
     public static void move(int disks, int from, int to) {
        if (disks &gt; 0) {
           int other = 6 - from - to; // sum of index 1+2+3=6
           System.out.println("Move disk from peg " + from + " to " + to);
           move(disks - 1, from, other);
           move(disks - 1, other, to);
           }
     }
  }
  </code></pre>
  
  <p>but the result is wrong. The solution in my book is</p>
  
  <pre><code>public class TowersOfHanoi {
     public static void main(String[] args) {
        move(5, 1, 3);
        }
  
     public static void move(int disks, int from, int to) {
        if (disks &gt; 0) {
           int other = 6 - from - to; // sum of index 1+2+3=6
           move(disks - 1, from, other);
           System.out.println("Move disk from peg " + from + " to " + to);
           move(disks - 1, other, to);
           }
     }
  }
  </code></pre>
  
  <p>why is this? I can't understand the ORDER of these expression:  </p>
  
  <ul>
  <li>first it run <code>System.out.println()</code></li>
  <li>then it run <code>move(disks - 1, from, other)</code></li>
  <li>now it run <code>System.out.println()</code> again or run <code>move(disks - 1, other, to)</code>?  </li>
  </ul>
  
  <p>and WHEN RESTART the block code? Thanx.</p>