1.递归求解汉诺塔问题
public static void move(char pos1,char pos2) {System.out.print(pos1+"->"+pos2+" ");
}public static void hanoi(int n,char pos1,char pos2,char pos3) {if(n == 1) {move(pos1,pos3);return;}hanoi(n-1,pos1,pos3,pos2);move(pos1,pos3);hanoi(n-1,pos2,pos1,pos3);
}
题目讲解:
2.递归求斐波那契数列的第 N 项
public class fib {public static int fib(int n) {if(n==1 || n==2)return 1;return fib(n-1)+fib(n-2);}public static void main(String[] args) {System.out.println(fib(10));}
}
3.