The Nth Fibonacci Java

PROGRAM TO PRINT Nth FIBONACCI NUMBER


import java.util.*;
  
class MAIN {
  
static int fib(int n) {
double phi = (1 + Math.sqrt(5)) / 2;
return (int) Math.round(Math.pow(phi, n) 
                        / Math.sqrt(5));
}
  
// Driver Code
public static void main(String[] args) {
        int n = 9;
    System.out.println(fib(n));
    }
}


OUTPUT
34

Comments

Popular posts from this blog

Solve the Sudoku Python

Solve the Sudoku Java

Find Duplicates Java