Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. public class fibNumber {
  2. public void nextFib(int[] num)
  3. {
  4. fibNumber test = new fibNumber();
  5. for(int i = 0; i < num.length; i++)
  6. {
  7. int j = 1;
  8. while(true)
  9. {
  10. if(test.fibonacciNumber(j) > num[i])
  11. {
  12. System.out.println(test.fibonacciNumber(j));
  13. break;
  14. }
  15. j++;
  16. }
  17. }
  18. }
  19.  
  20. public int fibonacciNumber(int n)
  21. {
  22. if(n == 1)
  23. return 1;
  24. else if(n == 2)
  25. return 1;
  26. else
  27. return fibonacciNumber(n - 1) + fibonacciNumber(n - 2);
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement