/* Towers of Hanoi * * Author: Carsten Butz * Date September 2002 */ import tio.*; class Hanoi{ public static void main (String[] args){ int howMany; System.out.print("How many disks do you want to move? "); howMany = Console.in.readInt(); while(howMany != 0) { move(howMany,1,3); System.out.print("How many disks do you want to move? "); howMany = Console.in.readInt(); } } public static void move(int n, int a, int b){ int c; if(n == 1) { System.out.println(a + " -> " + b); } else { // clever way of finding the number of the free pole: c = 6-(a+b); move(n-1,a,c); System.out.println(a + " -> " + b); move(n-1,c,b); } return; } }