Programming

How to Display Fibonacci Series in Java

October 23, 2014

Heyaaaaaa!  Advance Happy  Halloween everyone! Since its my semestral break A.K.A SEMBREAK just like before, I’m going to post some of my programming codes here which was taken previous semester.. here ya go.

Purpose: To display the “First 20 terms of Fibonacci Series.”

Output

Output

Source Code:

package fibonacci;

import java.util.*;
/**
*
* @author Christine Cloma
*/
public class Fibonacci {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner console = new Scanner (System.in);
int n, c, first = 0, second = 1, next;

System.out.println( “Enter number for Fibonacci: “);
n = console.nextInt();

System.out.println(“First ” + n + ” terms of Fibonacci series are : ” );

c = 1;
do
{
next = first + second;
first = second;
second = next;

System.out.print(next+ ” “);
c++;
}while(c<n);

}
}

 

PS: I used Netbeans IDE 8.0 version. 🙂

-tinay

You Might Also Like...

No Comments

    Leave a Reply

    This site uses Akismet to reduce spam. Learn how your comment data is processed.