Program to Solve Tower of Hanoi Problem


package javaFixer;

/**
 * Program #3 Program To Solve Tower of Hanoi
 * @author JavaFixer
 *
 */
public class TowerOfHanoi {
 public static void main(String[] args) {
  int n = 3;//No of Disk
  String start = "A";
  String mid = "B";
  String end = "C";
  getStep(n,start,mid,end);
 }

 private static void getStep(int n, String start, String mid, String end) {
  if(n==1){
   System.out.println(start+"->"+end);
  }
  else {
   getStep(n-1,start,end,mid);
   System.out.println(start+"->"+end);
   getStep(n-1,mid,start,end);
  }
 }
}


A->C
A->B
C->B
A->C
B->A
B->C
A->C