Title

JAVA

      In this blog, you will find programs on JAVA and also some help on how to write programs for JAVA...

December 18, 2014

WAP to print the Fibonacci Series uptil the term 'n' entered by the User

import java.util.*;
class Fibonacci
{
    public static void main()
    {
        int a = -1, b = 1;
        Scanner s=new Scanner(System.in);
        System.out.println("Enter the value for n: ");
        int n=s.nextInt();
        int c;
        for(int x = 1; x <= n; x++)
        {
            c = a + b;
            System.out.println(c);
            a = b;
            b = c;
        }
    }
}

No comments:

Post a Comment

Please write your comment in the box below...