package charpter07;
public class HanoiTower01Ex02 {
public static void main(String[] args) {
Tol tall = new Tol();
int num = 8;
tall.Tower(num,"T1","T2","T3");
}
}
class Tol{
public void Tower(int num,String a,String b,String c){
if(num == 1){
System.out.println(a + "->" + c);
}else{
Tower(num - 1,a,c,b);
System.out.println(a + "->" + c);
Tower(num - 1,b,a,c);
}
}
}
java 汉诺塔递归
最新推荐文章于 2023-04-13 11:24:22 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)