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