Dain1234 / Java-Programming

0 stars 0 forks source link

Sum of even fibonacci #8

Open Dain1234 opened 1 year ago

Dain1234 commented 1 year ago

package com.dain.logics;

import java.util.Scanner;

public class fibsumeven { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int f1 = 0; int f2 = 1; int f3 = 0; int f[] = new int[50]; System.out.println("Enter the number of terms:"); int n = sc.nextInt(); for (int i = 0; i <= n * 2; i++) {

        f[i] = f1;

        f3 = f1 + f2;
        f1 = f2;
        f2 = f3;
        System.out.print(f[i] + "\t");

    }
    System.out.println();
    System.out.println("The sum of numbers:");
    int sum = 0;
    for (int i = 0; i <= n * 2; i += 2) {
        sum = sum + f[i];
    }
    System.out.println(sum);

}

}