- Home
- Java Series Programs
Write a program in Java to find the sum of the given series:
Java Series Programs
Write a program in Java to find the sum of the given series:
S = x/2 + x/5 + x/8 + x/11 + …… + x/20
Answer
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 = i+3)
sum += (double)x / i;
System.out.println("Sum = " + sum);
}
}