详细步骤都在注释里
public class HanoiTower {
public static void hanoiTower(int n,String from,String to,String help)
{
//from:起点塔 help:辅助塔 to:目标塔
/*
* 解题思路:
* 假设有A,B,C三个塔
* 将n个圈从A塔挪到B塔,
* 相当于将n-1个圈从A塔借助B塔挪到C塔
* 再把第n个圈从A挪到B塔
* 最后把n-1个圈从C塔借助A塔挪到B塔
* */
if(n==1) {
System.out.println("move"+n+"from"+from+"to"+to);
return ;
}
hanoiTower(n-1,from,help,to);
System.out.println("move"+n+"from"+from+"to"+to);
hanoiTower(n-1,help,to,from);
}
public static void main(String[] args) {
hanoiTower(3,"A","B","C");
}
}