Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- This method demos the recursive fib method.
- */
- public class Project1
- {
- public static void main(String [] args)
- {
- System.out.println("The first 20 numbers in " +
- "the Fibonacci series are: ");
- for (int i=0;i<20;i++)
- System.out.print(fib(i) + " ");
- System.out.println();
- }
- /**
- The Fib method calculates the nth number
- in the Fibonacci series.
- @parm n The nth number to calculate.
- @return The nth number.
- */
- public static int fib(int n)
- {
- if (n== 0)
- return 0;
- else if (n==1)
- return 1;
- else
- return fib(n-1) + (n-2);
- }
- }
Add Comment
Please, Sign In to add comment