Gadgets

Showing posts with label fibonacci series. Show all posts
Showing posts with label fibonacci series. Show all posts

Tuesday, 24 November 2015

Fibonacci series program in java

Fibonacci series program in java
The main aim of Fibonacci series that we add current number+ previous number= result, here I shown in the diagram clearly. Initially first we add current number two times after that we add current number+ previous number.

public class Fibonacci {
    public static void main(String s[]){
        int n=10,i,f0=1,f1=1,f2=0;
               for(i=1;i<=n;i++)
               {
                 f2=f0+f1;
                 f0=f1;
                 f1=f2;
                 f2=f0;
          System.out.println(f2);
               }
    }    
}
 
Output:
1
2
3
5
8
13
21
34
55
89
Explanation in diagram