// This recursive program prints out all the moves // necessary to solve the original towers of hanoi problem. public class towers { // Print out the moves for moving number disks from tower start // to tower end. public static void printmoves(int start, int end, int number) { // There's work to do only if we have more than 0 disks. if (number > 0) { int other = 6 - start - end; // Move all of the disks except the bottom to the other pole. printmoves(start, other, number-1); // Print the move for the bottom disk. System.out.print("Move disk #"+number+" from pole "+start); System.out.println(" to pole "+end); // Move all the disks from the other pole to the end pole. printmoves(other, end, number-1); } } public static void main(String[] args) { printmoves(2,1,10); } }