Solutions for Class 10 ICSE Logix Kips Computer Applications with BlueJ Java | IT Developer <?php echo $page_title; ?>
IT Developer

Iterative Constructs in Java

Chapter 9

Iterative Constructs in Java

Class 10 - Logix Kips ICSE Computer Applications with BlueJ


Share with a Friend

Java Program: Compute Series Sum


28. Write a program to read the number x using the Scanner class and compute the series:

Sum = x/2 + x/5 + x/8 + x/11+ ..... + x/20

The output should look like as shown below:

Enter the value of x: 10
Sum of the series is: 10.961611917494269


Program Title: Compute Series Sum

Series Used

\[ Sum = \frac{x}{2} + \frac{x}{5} + \frac{x}{8} + \frac{x}{11} + \cdots + \frac{x}{20} \]

import java.util.Scanner;

 

public class SeriesSum {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

 

        System.out.print("Enter the value of x: ");

        double x = sc.nextDouble();

 

        double sum = 0.0;

 

        // Denominators: 2, 5, 8, 11, 14, 17, 20 (increasing by 3)

        for (int denominator = 2; denominator <= 20; denominator += 3) {

            sum += x / denominator;

        }

 

        System.out.println("Sum of the series is: " + sum);

 

        sc.close();

    }

}

Output

Sample Input / Output
Enter the value of x: 10
Sum of the series is: 10.961611917494269

📝 Explanation

  1. Denominators in the series follow an arithmetic progression: 2, 5, 8, 11, 14, 17, 20
    • Difference between terms = 3
  2. Each term = x / denominator
  3. Loop through the denominators and add each term to the sum
  4. Print the final sum as double to retain precision.