import java.util.Scanner ; public class TowersOfHanio { // from page 180 of // Janet J. Prichard and Frank M. Carrano // Data Abstraction & Problem Solving with Java: Walls & Mirros public static void solveTowers(int count, char source, char destination, char spare) { if (count == 1) { System.out.println("Move top disk from pole " + source + " to pole " + destination); } else { solveTowers(count-1, source, spare, destination); // X solveTowers(1, source, destination, spare); // Y solveTowers(count-1, spare, destination, source); // Z } // end if } // end solveTowers public static void main(String[] args) { System.out.println("Enter the size of the tower"); Scanner stdIn = new Scanner(System.in) ; int size = stdIn.nextInt() ; solveTowers(size, 'L', 'R', 'C') ; } }