The Fibonacci sequence was my exposure to math classes in junior high school, and the only thing that was interested in that was his name, because he had been thinking about who had a so awkward name ... Later ignorant I found that the original is such a thing:
Fibonacci sequence: The 1202 Leonardo Fibonacci proposed, was just to solve a rabbit breeding problem, and then the world's research and development, found that he has a very wide range of applications. Here we use the program to implement how to calculate the Fibonacci sequence:
0,1,1,2,3,5,8,13,21,34 ...
The above sequence has a recursive and an initial condition:
F[n]=f[n-1]+f[n-2] (n>1)
F[0]=0, F[1]=1
According to the above conditions we will write the program:
Public classfib{ Public Static void Main(String args[]) {intn=Ten;int[]f=New int[n]; f[0]=0; f[1]=1; for(intI=2; i<n;i++) {f[i]=f[i-1]+f[i-2]; } System. out. println ("The first 10 Fibonacci sequences are:"); for(intj=0; j<n;j++) {System. out. Print (f[j]+" "); } }}
Did you see the Fibonacci sequence in fact not so scary ... It's just a scary name. < ^^ >
Java implementation-Fibonacci sequence