Hanoi01

摘要:Hanoi01


import java.io.*;
public class Hanoi01
{ public static int step=0;

public static void H(int n,char x,char y,char z)
  {if(n==1)
    {++step;
     System.out.println(step+">"+n+":"+x+"->"+z);
     return;
    }
   H(n-1,x,z,y);
    ++step;
    System.out.println(step+">"+n+":"+x+"->"+z);
   H(n-1,y,x,z);
    return;
  }
public static void main(String[] argv)
   {H(4,'A','b','c');
    return;
   }
}