Java program to find Fibonacci series of a given number

Friday, February 4th, 2011

Java program to find Fibonacci series of a given number

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*Write a program to find Fibonacci series of a given no.
  Example :
  Input - 8
  Output - 1 1 2 3 5 8 13 21
 */
class Fibonacci{
	public static void main(String args[]){
		int num = Integer.parseInt(args[0]); //taking no. as command line
		argument.
			System.out.println("*****Fibonacci Series*****");
		int f1, f2=0, f3=1;
		for(int i=1;i<=num;i++){
			System.out.print(" "+f3+" ");
			f1 = f2;
			f2 = f3;
			f3 = f1 + f2;
		}
	}
}

Author Name :
surajk

Total : 53 Comments


53 Responses to “Java program to find Fibonacci series of a given number”

  1. vaishali says:

    how to print this-
    0,1,1,2,3

  2. Javin says:

    Here is the recursive version of Fibonacci Series in Java http://java67.blogspot.sg/2012/07/java-program-fibonacci-series-with.html

  3. yuvraj says:

    if u will provide output also this is better for some ordinary programmer

Leave a Reply

Question and Answer
C/C++ Unix & Linux Wordpress
Source codes
C C++ Java

Free email signup

Email: