ICSE Class 10 Computer Applications
Question 32 of 69
Iterative Constructs in Java — Question 32
Back to all questions 32
Question Question 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
import java.util.Scanner;
public class KboatSeries
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter x: ");
int x = in.nextInt();
double sum = 0.0;
for (int i = 2; i <= 20; i += 3)
sum += (double)x / i;
System.out.println("Sum = " + sum);
}
}Output
