Advertisement
Guest User

Untitled

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