MCPcopy Create free account
hub / github.com/chaharnishant11/CodeIn10DSA / nfibonacci

Class nfibonacci

Recursion/Code/nthFibonacci.java:2–31  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import java.util.*;
2class nfibonacci
3 {
4
5 static int fibo(int n)
6 {
7 if(n==0) // base condition;
8 return 0;
9
10 if(n==1)
11 return 1;
12
13 //small calculation
14 int recResult1 = fibo(n-1);
15 int recResult2 = fibo(n-2);
16 int smallCal = recResult1+recResult2;
17
18 return smallCal;
19
20 }
21
22 // Driver Code
23 public static void main(String args[])
24 {
25 Scanner in = new Scanner(System.in); // to take input we use scanner class.
26 System.out.print("Enter a number : ");
27 int n = in.nextInt();
28
29 System.out.println("Fibonacci num of " + n + " is : " + fibo(n));
30 }
31}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected