Fibonacci Series in Java


public class Fibonacci {
   public static void main(String[] args) {
               
                //array of numbers to be checked
                  int n=20;
        int a = 0;
        int b = 1;
        System.out.print(a+", "+b);
        for(int i=1;i<=n;i++) {
            int c = a + b;
            System.out.print(", "+c);
            a = b;
            b = c;
        }
        System.out.println();
    }
    
}

Share this article on