public class Recursion {
/**
* @Title: main
* @Description: TODO
* @param args
*/
public static void main(String[] args) {
//test();
System.out.println(test2(3));
test3(100);
System.out.println(test4(100));
System.out.println(fiboncaai(4));
}
public static int fiboncaai(int n) {
if(n == 1 || n ==2) {
return 1;
} else {
return fiboncaai(n - 1) + fiboncaai(n - 2);
}
}
public static int test4(int n) {
if(n == 1) {
return 1;
}else {
return n + test4(n-1);
}
}
public static void test3(int n) {
System.out.println(n);
if(n == 2) {
return ;
}
test3(n-1);
}
public static int test2(int n) {
if(n == 1 || n == 0) {
return 1;
} else {
return n* test2(n-1);
}
}
}
递归
最新推荐文章于 2018-06-05 13:17:41 发布