Thursday, 28 August 2014

Fibonacci Series in Java

Structure of the Problem Requirements 

In this problem we will learn how to make a Fibonacci Series in Java Program. Fibonacci series is a mathematical problem in which the third term is the sum of previous two terms. Fibonacci series is like  1 1 2 3 5 8 and it clear that the previous two terms make third term . Here is the source code of this example which help you in better understanding.

Source Code

import java.util.Scanner;

public class Fibonacci{
public static void main(String[] args) {
    Scanner input = new Scanner (;
    int num;
    long previous =1, next =0,sum;
    System.out.println(" Enter Your Number to Find its Fibonacci ");
    num = input.nextInt();
    while (next<num/2)
        System.out.print(previous+ " ");
        sum = previous+next;
        next = previous;
        previous = sum;

Output of the Program

Fibonacci Series
Fibonacci Series output 

Share it Please

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.


Post a Comment