Computer Applications
Write a program in Java to find the sum of the given series:
S = a2 + a2 / 2 + a2 / 3 + …… + a2 / 10
Java
Java Iterative Stmts
198 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 a: ");
int a = in.nextInt();
double sum = 0.0;
for (int i = 1; i <= 10; i++)
sum += Math.pow(a, 2) / i;
System.out.println("Sum = " + sum);
}
}
Variable Description Table
Program Explanation
Output
Answered By
77 Likes
Related Questions
Write a program in Java to find the sum of the given series:
S = (a*2) + (a*3) + …… + (a*20)
Write a program to input a number and display the new number after reversing the digits of the original number. The program also displays the absolute difference between the original number and the reversed number.
Sample Input: 194
Sample Output: 491
Absolute Difference= 297Write a program in Java to find the sum of the given series:
S = a + a2 / 2 + a3 / 3 + …… + a10 / 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=5