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
Java
Java Iterative Stmts
ICSE 2008
56 Likes
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);
}
}
Variable Description Table
Program Explanation
Output
Answered By
27 Likes