Current location - Training Enrollment Network - Mathematics courses - You'd better explain how to program with Java program. Topic: classic question: there are a pair of rabbits, which have a pair every month since the third month after birth.
You'd better explain how to program with Java program. Topic: classic question: there are a pair of rabbits, which have a pair every month since the third month after birth.
This topic examines the use of recursive (sequential) ideas to solve problems.

Assume that in the 24th month, the sample code is as follows:

Public class woo {

Public static void main (strinargs []) {

system . out . println(fib(24));

}

Dedicated static internal optical fiber (internal n)

if (n == 1 || n == 2) {

Returns1;

} Otherwise {

Return fiber (n-1)+fiber (n-2);

}

}

}

Extended data:

Fibonacci series, also known as the golden section series, was introduced by the mathematician Leonardo Fibonacci taking raising rabbits as an example, so it is also called "rabbit series", which refers to such a series: 1, 1, 2, 3, 5, 8, 65433.

Mathematically, the recursive definition of Fibonacci sequence is as follows: F( 1)= 1, f (2) = 1, f (n) = f (n- 1)+f (n-2) In modern physics and quasicrystals,

References:

Baidu Encyclopedia: Fibonacci Sequence

Baidu Encyclopedia: Recursive Function