/* Java Program For Generating Fibonacci Sequence Is Defined by The Following Rule:
The first two values in the sequence are 1 & 1. Every subsequent value is the
sum of two values preceding it.*/
// File Name: fibonacci.java
import java.io.*;
class fibonacci
{
public static int fib(int n) {
if (n <= 1)
return n;
else
return fib(n-1) + fib(n-2);
}
public static void main(String args[])
{
int temp = Integer.parseInt(args[0]);
for (int i = 1; i <= temp; i++)
{
System.out.print(fib(i)+",");
}
System.out.println("\n");
System.out.println("www.shashanktechnologies.blogspot.com");
}
}
OUTPUT:
COMPILATION: G:\shashank>javac fibonacci.java
INTERPRETATION: G:\shashank>java fibonacci 10
No comments:
Post a Comment