KnowledgeBoat Logo
|

Computer Applications

Write a program in Java to find the sum of the given series:

x+13+x+25+x+37+...to n terms\dfrac{x + 1}{3} + \dfrac{x + 2}{5} + \dfrac{x + 3}{7} + …\text{to n terms}

Java

Java Iterative Stmts

1 Like

Answer

import java.util.Scanner;

public class KboatSeries
{
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter n: ");
        int n = in.nextInt();
        System.out.print("Enter x: ");
        int x = in.nextInt();

        double sum = 0;
        for (int i = 1, j = 3; i <= n; i++, j += 2) {
            sum += (x + i) / (double)j;
        }
        System.out.println("Sum = " + sum);
    }
}

Output

BlueJ output of Write a program in Java to find the sum of the given series:

Answered By

1 Like


Related Questions