shivamisone

fibonaci

Sep 27th, 2023
988
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | Source Code | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class fibo {
  4.     static int a = 0, b = 1, s = 0, n = 0;
  5.  
  6.     public static void main(String[] args) {
  7.         Scanner sc =15 new Scanner(System.in);
  8.         System.out.println("enter what position number you want from fibonaci series");
  9.         n = sc.nextInt() - 2;
  10.         int p = loops(0, 1);
  11.         System.out.println(p);
  12.     }
  13.  
  14.     public static int loops(int x, int y) {
  15.         if (n != 0) {
  16.             s = x + y;
  17.             n -= 1;
  18.             return loops(y, s);
  19.         } else {
  20.             return s;
  21.         }
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment