KnowledgeBoat Logo

Java Series Programs

Write the program to find the sum of the following series:

S = (a/2) + (a/5) + (a/8) + (a/11) + ……. + (a/20)

Java

Java Iterative Stmts

ICSE

29 Likes

Answer

import java.util.Scanner;

public class KboatSeries
{
    public void computeSeriesSum() {

        Scanner in = new Scanner(System.in);
        System.out.print("Enter a: ");
        int a = in.nextInt();
        double sum = 0;

        for (int i = 2; i <= 20; i = i + 3) {
            sum += a / (double)i;
        }
        
        System.out.println("Sum=" + sum);
    }
}

Output

BlueJ output of Write the program to find the sum of the following series: (c) S = (a/2) + (a/5) + (a/8) + (a/11) + ……. + (a/20)

Answered By

13 Likes