Advertisement
Guest User

Fibonacci

a guest
Oct 23rd, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.47 KB | None | 0 0
  1. package com.codewithDZM;
  2.  
  3. import java.util.*;
  4.  
  5. public static int fibonacci (int n)
  6. {
  7. if (n<2)
  8. {
  9. return n;
  10. }
  11. else
  12.  
  13. return ( (fibonacci (n-1) ) + ( fibonacci (n-2) ) );
  14. }
  15.  
  16.  
  17.  
  18. public class Main
  19. {
  20.  
  21. public static void main(String[] args)
  22. {
  23. int x;
  24. Scanner sc = new Scanner (System.in);
  25.  
  26. System.out.println ( fibonacci (x) );
  27. }
  28.  
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement