标签:应用 [] out main div 斐波那契数列 实现 斐波那契数 char
package ch06; public class Fibonacci { public static int getNumber(int n) { if(n == 1) { return 0; } else if(n == 2){ return 1; } else { return getNumber(n - 1) + getNumber(n - 2); } } }
package ch06; public class TestFibonacci { public static void main(String[] args) { System.out.println(Fibonacci.getNumber(5)); } }
package ch07; public class HanoiTower { /** * 移动盘子 * topN:移动的盘子数 * from:起始塔座 * inter:中间塔座 * to:目标塔座 */ public static void doTower(int topN, char from, char inter, char to) { if (topN == 1) { System.out.println("盘子1,从" + from + "塔座到" + to + "塔座"); } else { doTower(topN - 1, from, to, inter); System.out.println("盘子" + topN + ",从" + from + "塔座到" + to + "塔座"); doTower(topN - 1, inter, from, to); } } }
package ch07; public class TestHanoiTower { public static void main(String[] args) { HanoiTower.doTower(5, ‘A‘, ‘B‘, ‘C‘); } }
标签:应用 [] out main div 斐波那契数列 实现 斐波那契数 char
原文地址:https://www.cnblogs.com/tangxlblog/p/9973225.html