JAVA语法——汉诺塔问题

package 汉诺塔问题;

public class 汉诺塔问题 {
    public static void moveDish(int level, char from, char inter, char to)
    {
        if(level == 1)
            System.out.println("从"+from+"移动盘子 1 号到"+to);
        else
        {
            moveDish(level-1,from,to,inter);
            System.out.println("从"+from+"移动盘子 "+level+" 号到"+to);
            moveDish(level-1,inter,from,to);
        }
    }
    
    public static void main(String[] args)
    {
        int nDisks = 3;
        
        moveDish(nDisks,'A','B','C');
    }
}

 

posted @ 2018-12-19 21:56  JAYPARK01  阅读(229)  评论(0编辑  收藏  举报