递归实现汉诺塔问题

public class HanoiTower
{ 
    public static void main(String[] args)throws Exception
    {
        hanoiTower(64,"X","Y","Z");
    } 
    
    public static void hanoiTower(int n, String x, String y, String z)
    {
        if(n == 1)
        {
            System.out.println(x+"-->"+z);
            return;
        }
        else
        {
            hanoiTower(n-1,x,z,y);
            System.out.println(x+"-->"+z);
            hanoiTower(n-1,y,x,z);
        }
    }
}
原文地址:https://www.cnblogs.com/kuillldan/p/5701441.html