- Home
- Chapter 1 - Object Oriented Programming Concepts
- Object Oriented Programming Concepts
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 2 - Introduction to Java
- Introduction to Java
- Multiple Choice Questions
- Assignment Questions
- Chapter 3 - Values and Data Types
- Values and Data Types
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 4 - Operators in Java
- Operators in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 5 - User-Defined Methods
- User-Defined Methods
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions
- Chapter 6 - Input in Java
- Input in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 7 - Mathematical Library Methods
- Mathematical Library Methods
- Multiple Choice Questions
- Assignment Questions
- Chapter 8 - Conditional Constructs in Java
- Conditional Constructs in Java
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 9 - Iterative Constructs in Java
- Iterative Constructs in Java
- Multiple Choice Questions
- State whether the given statements are True or False
- Assignment Questions and Programs
- Chapter 10 - Nested for loops
- Nested for loops
- Assignment Questions and Programs
- Chapter 11 - Constructors
- Constructors
- Multiple Choice Questions
- Assignment Questions and Programs
- Chapter 12 - Library Classes
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 13 - Encapsulation and Inheritance
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 14 - Arrays
- Library Classes
- Multiple Choice Questions
- Assignment Questions
- Chapter 15 - String Handling
- Library Classes
- Multiple Choice Questions
- Assignment Questions
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
- Denominators in the series follow an arithmetic progression: 2, 5, 8, 11, 14, 17, 20
- Difference between terms = 3
- Each term = x / denominator
- Loop through the denominators and add each term to the sum
- Print the final sum as double to retain precision.
