package hanoi; public class Hanoi2 { /* Recursive procedure to move the disk at a height from one pin to another pin using a third pin. */ private void moveTower(int height, int fromPin, int toPin, int usingPin) { if (height > 0) { this.moveTower(height-1, fromPin, usingPin, toPin); this.moveDisk(fromPin, toPin); this.moveTower(height-1, usingPin, toPin, fromPin); } } /* Move a disk from a pin to another pin. Print the results in the console window. */ private void moveDisk(int fromPin, int toPin) { System.out.println(fromPin + " -> " + toPin); } /* Main: Create the object and invoke the moveTower method. */ public static void main(String args[]) { (new Hanoi2()).moveTower(3, 1, 3, 2); } }