复制代码 代码如下:
package com.tiantian.algorithms;
public class HanoiTowerTest {
public static void main(String[] args) {
doTowers(4, 'A', 'B', 'C');
}
public static void doTowers(int topN, char from, char inter, char to){
if(topN == 1){
System.out.println("最后把木块1从" + from + "移动到" + to);
}else{
doTowers(topN - 1, from, to, inter); // 调用(XX)
System.out.println("把木块" + topN + "从" + from + "移动到" + to);
doTowers(topN - 1, inter, from ,to); // 调用(YY)
}
}
}



