fibonacci sequence algorithm in java

Solutions on MaxInterview for fibonacci sequence algorithm in java by the best coders in the world

showing results for - "fibonacci sequence algorithm in java"
Giovanni
22 Nov 2019
1public class Fibonacci_sequence {
2	
3	static int fib(int n) {
4		if( n <= 0 ) {
5			return 0;
6		}else if( n == 1 ) {
7			return 1;
8		}else {
9			return ( fib( n - 1 )+ fib( n - 2 ));
10		}
11		
12	}
13	
14	public static void main(String[] args) {
15		
16		int n = 9;
17		System.out.println(fib(n));
18		
19		// TODO Auto-generated method stub
20
21	}
22
23}
24