Java Program For The Fibonacci Series

Java Program For The Fibonacci Series

Java Program For The Fibonacci Series


import java.util.Scanner:

public class Fibonacci  {
     public static void main(String[ ] args)  {
           int num, a = 0, b = 0, c =1;
           Scanner in = new scanner(System.in);
           System.out.println( "Enter the number of times" );
           num = in.nextInt( );
           System.out.println( "Fibonacci Series of the number is: " );
           for (int i=0; i<=num; i++)   {
                 a = b;
                 b = c;
                 c = a+b;
                 System.out.println( a + "");

            }

       }

 }


Output:

Enter the number of times
9
Fibonacci series of the number is:
0
1
1
2
3
5
8
13
21
34

0 comments 10:

Post a Comment