java算法递归之汉诺塔

    科技2025-07-20  6

    package 递归; public class 汉诺塔 { public static void main(String[] args) { test01(5,"A","B","C"); } //代码实现 public static void test01(int N ,String from, String to ,String help ){ if (N == 1){ System.out.println("move"+N+"from"+from+"to"+to); }else { // test01(N-1,from,help,to);//先把N-1个盘子放到 System.out.println("move"+N+"from"+from+"to"+to); test01(N-1,help,to,from); } } }
    Processed: 0.009, SQL: 8