// Project: Recursion // Module: hanoi1 // Source code file: Main.java // Solve the Towers of Hanoi Puzzle // using the standard recursive algorithm. public class Main { public static void main(String[] args) { int nDisks; try { nDisks = Integer.parseInt(args[0]); hanoi(nDisks, "A", "B", "C"); } catch(NumberFormatException e) { System.out.println( "Illegal input for number of disks."); } } public static void hanoi( int n, String from, String to, String aux) { if (n >= 1) { hanoi(n - 1, from, aux, to); System.out.println(from + " to " + to); hanoi(n - 1, aux, to, from); } } }