You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

548 B

汉偌塔问题

  • 问题分析

    • 1、把n-1个圆盘从A经过C移动到B
    • 2、把第n个圆盘从A移动到C
    • 3、把n-1个圆盘从B经过A移动到C
  • 原理

  • 代码

    public static void main(String[] args) {
        run(3, "A", "B", "C");
    }

    private static void run(Integer n, String a, String b, String c) {
        if (n>0) {
            run(n-1, a, c, b);
            System.out.println("从【"+a+"】移动到【"+c+"】");
            run(n-1, b, a, c);
        }
    }