java 小程序-- 汉诺塔

1.code

    public static void main(String[] args) {
        int level = 4;
        moveDish(4, 'A', 'B', 'C');

    }

    public static void moveDish(int level, char from, char inter, char to){
        if(level==1){
            System.out.println("" + from  + "移动" + level + "号盘到" +  to );
        }else{
            moveDish(level-1, from, to, inter);
            System.out.println("" + from  + "移动" + level + "号盘到" +  to );
            moveDish(level-1, inter, from, to);
        }
    }

2. 效果图

posted @ 2016-09-22 16:58  fangfan  阅读(319)  评论(0编辑  收藏  举报