A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© Aaron9527 中级黑马   /  2016-6-2 22:32  /  612 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

package cn.itcast.递归;

public class Hanno {
        public static void main(String[] args) {
                trans(3,'A','B','C');
        }
        public static void trans(int n,char from,char to,char temp){
                if(n==1){
                        System.out.println(from+"--------->"+to);
                }
                else{
                        trans(n-1,from,temp,to);
                        System.out.println(from+"--------->"+to);
                        trans(n-1,temp,to,from);
                }
        }
}
/*
下面两个递归不是很明白
*/

1 个回复

倒序浏览
还没学递归,过来暖贴,坐等大神解答
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马