• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

1、说到递归就不得不说菲波那契数列,F(1)=1,F(2)=1,F(n)=F(n-1) F(n-2)(n=3,nN*),相当于每次都是自己调用了自己;

萨姆顿这个方法是求0-N之和,可以理解成普通与萨姆顿(N-1)之和,即sumToN(0)=0,sumToN(N)=sumToN(N-1)N(NN *);

一公共类递归{

2 /**

3 *之和.没有循环,但是使用了堆栈。

4 *

5 * @param paraN给定值。

6 * @返回总和。

7 */

8公共静态int sumToN(int paraN) {

9 if (paraN=0) {

10 //基础。

11返回0;

12 } //Of if

13

14返回萨姆顿(paraN-1)paraN;

15 } //的萨姆顿

16

17 /**

18 *斐波那契数列。

19 *

20 * @param paraN给定值。

21 * @返回总和。

22 */

23 public static int Fibonacci(int paraN){

24 if (paraN=0) {

25返回0;

26 } if (paraN==1) {

27返回1;

28 }//Of if

29返回斐波那契(paraN - 1)斐波那契(paraN-2);

30 }//的斐波那契

31

32 public static void main(String args[]){

33 int temp值=5;

34系统。出去。println(' 0 sum to ' temp value sumToN(temp value));

35 temp值=-1;

36系统。出去。println(' 0 sum to ' temp value sumToN(temp value));

37

38 for(int I=0;i 10i ) {

39 System.out.println('斐波那契我' : '斐波那契);

40 } //的因为我

主要的的41 } //的

42 } //的类递归

Link to comment
Share on other sites