public class HanoiTower {
public static void main(String[] args) {
int n = 3; // 圆盘的数量
char from = 'A'; // 起始柱子
char aux = 'B'; // 辅助柱子
char to = 'C'; // 目标柱子
solveHanoi(n, from, aux, to);
}
public static void solveHanoi(int n, char from, char aux, char to) {
if (n == 1) {
System.out.println("Move disk 1 from " + from + " to " + to);
return;
}
solveHanoi(n - 1, from, to, aux);
System.out.println("Move disk " + n + " from " + from + " to " + to);
solveHanoi(n - 1, aux, from, to);
}
}
标签:柱子,21,char,aux,打卡,solveHanoi,public
From: https://www.cnblogs.com/wlxdaydayup/p/17572478.html