Java Source Code

/* Author: Hannes du Plooy */
/* Date: 20 Sep 2016       */
/* Objective: To solve the towers of hanoi with number of discs provided in the arguments to calling the program */

public class TowersOfHanoi {
    static void hanoi(int source, int dest, int other, int discs) {
        if (discs <= 0)
            return;
        hanoi(source,other,dest,discs-1);
        System.out.printf("Move from %d to %d\n",source,dest);
        hanoi(other,dest,source,discs-1);
    }

    public static void main(String []args) {
        if (args.length < 1) {
            System.out.println("Please provide the number of discs!");
        } else {
            hanoi(0,2,1,Integer.parseInt(args[0]));
        }
    }
}