Tuesday, 3 January 2017

Fibonacci Series in Java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.Scanner;
class Fabonacci
{
    public static void main(String[] args)
    {
        // declare variable
        int FirstNumber,SecondNumber;
        // initialize variable
        FirstNumber = 1;
        SecondNumber = 1;
        //taking input from user using Scanner class
        System.out.println("Plase Enter Number For Generate Fabonacci Series");
        Scanner scan = new Scanner(System.in);
        int Val = scan.nextInt();
        while(FirstNumber < Val)
        {
            System.out.println(FirstNumber);
            FirstNumber = FirstNumber + SecondNumber;
            SecondNumber = FirstNumber - SecondNumber;
        }
    }
}

No comments:

Post a Comment