JAVA PROGRAM 1

itprofessionalsrocks.blogspot.com
JAVA PROGRAM 1:
TO CALCULATE FIBONACCI SERIES IN JAVA RECURSIVELY.
import java.util.*;
class fibo
{
public static int fib(int num)
{int f;
if(num==1)
return 0;
if(num==2)
return 1;
else
f=fib(num-1)+fib(num-2);
return f;
}
       public static void main(String args[])
       {
       Scanner obj=new Scanner(System.in);
        int i;
       System.out.println("enter number of elements to be generated");
       int num=obj.nextInt();
       for(i=1;i<=num;i++)
       System.out.println(fib(i));
       }
   
}
FOR OUTPUT JUST PASTE THIS IN BIN FOLDER AND DO AS BELOW:
JAVAC FIBO.JAVA
JAVA FIBO
THEN BY PRINTSCREEN AND PASTE IT IN PAINT .....

Comments