Write a Java program that uses both recursive and non recursive functions to print the nth value in the Fibonacci sequence. - Code

Latest

programs

Monday, October 10, 2011

Write a Java program that uses both recursive and non recursive functions to print the nth value in the Fibonacci sequence.


Write a Java program that uses both recursive and non recursive functions to print the nth value in the Fibonacci sequence.
import java.io.*;
import java.lang.*;
class fibonacci
{
public static void main(String args[]) throws IOException
{
int a=Integer.parseInt(args[0]);
int b=Integer.parseInt(args[1]);
int n=Integer.parseInt(args[2]);
int c=0;
while(c<n)
{
c=a+b;
System.out.print(c);
a=b;
b=c;
}
}
}

No comments:

Post a Comment