Java?????????
???????????? ???????[ 2013/1/10 10:18:24 ] ????????
?????μ??????????????????????????Щ??????????????????????????????
???????????????????????????????顣
?????????????????????????饗 recursion????????????????????????????й???á? ?????????????????????????????????????????????????????????????????????????????????????????????С???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
??????????????????
????1?????????
????2??????????
????3????鷵???
????????????????????????????????????????????????鷵???
?????????????????????????????
????1?????Java??????5???????5????=5*4*3*2*1??
package org.wxp.recursion;
/**
* ????5????(result = 5*4*3*2*1)
* @author Champion.Wong
*
*
*/
public class Test01 {
public static void main(String[] args) {
System.out.println(f(5));
}
public static int f(int n) {
if (1 == n)
return 1;
else
return n*(n-1);
}
}
?????????У????????????????????????
??????1?????????????????????????????1?????????1????????е????
??????2?????????Σ???????????????1??????????????????
??????3????鷵??Σ?????????????????????????5???????5*4????5*??5-1??????n*??n-1??
????2?????Java?????????У?1??1??2??3??5??8......??40λ????
package org.wxp.recursion;
/**
* ?????У?1??1??2??3??5??8......??40λ????
* @author Champion.Wong
*
*/
public class Test_02_Fibonacci {
public static void main(String[] args) {
System.out.println(f(6));
}
public static int f(int n ) {
if (1== n || 2 == n)
return 1;
else
return f(n-1) + f(n-2);
}
}
???????????????????3λ?????????λ???????λ???????????????λ?????????????λ????????????????????м???
??????1?????????λ???1??2?????????????????1??
??????2???????λ???3???????????=2=1+1??
??????λ???4????????=3=2+1??
??????λ???5????????=5=3+2??
??????λ???6????????=8=5+3??
????......
??????3?????2??????????????3??????£????λ????n???????=f??n-1??+f??n-2??
??????????Щ?????????????鼴?????????????????????????????????????д???????????????????????????д??????????“???????”????????е??????????????????????????????????????·?????????????????????????????????????????????????????????????????????????????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11