Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Fib2 {
- public static void main(String[] args) {
- int i = 14;
- System.out.println(fib(i));
- //Fibonacci numbers : 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377;
- //ordinal number : 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14;
- }
- static int fib (int i) {
- if (i == 1) {return 1;}
- if (i == 2) {return 1;}
- else {
- return fib(i - 1) + fib(i - 2);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement