Computer Applications
Write a program in Java to find the sum of the given series:
S = a + a2 / 2 + a3 / 3 + …… + a10 / 10
Answer
import java.util.Scanner;
public class KboatSeries
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a: ");
int a = in.nextInt();
double sum = 0.0;
for (int i = 1; i <= 10; i++)
sum += Math.pow(a, i) / i;
System.out.println("Sum = " + sum);
}
}
Variable Description Table
Program Explanation
Output
Related Questions
Write a program in Java to find the sum of the given series:
S = a2 + a2 / 2 + a2 / 3 + …… + a2 / 10
The Greatest Common Divisor (GCD) of two integers is calculated by the continued division method. Divide the larger number by the smaller, the remainder then divides the previous divisor. The process repeats unless the remainder reaches to zero. The last divisor results in GCD.
Sample Input: 45, 20
Sample Output: GCD=5Write a program in Java to find the sum of the given series:
S = (a*2) + (a*3) + …… + (a*20)
Write the program to find the sum of the following series:
S = a + a2 + a3 + ……. + an