Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions Java/Language/SumOfFibonacciSeries.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Author: Raviteja
Date: 08/10/202
Description: This code finds even sum of fibonacci series till number n
*/
import java.io.*;

class SumOfFibonacciSeries {

// Computing the value of first fibonacci series
// and storing the sum of even indexed numbers
static int Fib_Even_Sum(int N) {
if (N <= 0) {
return 0;
}

int fib[] = new int[2 * N + 1];
fib[0] = 0;
fib[1] = 1;

// Initializing the sum
int s = 0;

// Adding remaining numbers
for (int j = 2; j <= 2 * N; j++) {
fib[j] = fib[j - 1] + fib[j - 2];

// Only considering even indexes
if (j % 2 == 0) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check this indentaion. Use the code formatter mentioned in the contribution guidelines.

s += fib[j];
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the indentation for the if block

}

return s;
}

// The Driver code
public static void main(String[] args) {
int N = 11;

// Prints the sum of even-indexed numbers
System.out.println(
"Even sum of fibonacci series till number " + N +
" is: " + +Fib_Even_Sum(N));
}
}