Sum of Fibonacci Numbers | Set 2 | Java program for the above approach ; Function to find the sum of first N + 1 fibonacci numbers ; Apply the formula ; Print the result ; Driver Code
import java . io . * ; class GFG { public static void sumFib ( int N ) { long num = ( long ) Math . round ( Math . pow ( ( Math . sqrt ( 5 ) + 1 ) / 2.0 , N + 2 ) / Math . sqrt ( 5 ) ) ; System . out . println ( num - 1 ) ; } public static void main ( String [ ] args ) { int N = 3 ; sumFib ( N ) ; } }