/* File: Hanoi.java - March 2011 */ package l04; /** * Display the list of moves required to solve the towers of Hanoi * problem using a recursive algorithm * * Sample usage: java l04.Hanoi 5 * * @author Michael Albert * */ public class Hanoi{ public static void main(String[] args){ hanoi(Integer.parseInt(args[0]), "A", "B", "C"); } public static void hanoi(int n, String source, String dest, String extra) { if (n == 0) return; hanoi(n-1, source, extra, dest); System.out.println(source + " --> " + dest); hanoi(n-1, extra, dest, source); } }