Computer Applications
Write a program in Java to find the sum of the given series:
1 + 3/(1+2+3) + 5/(1+2+3+4+5) + …. to n terms
Java
Java Iterative Stmts
2 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 n: ");
int n = in.nextInt();
double sum = 0;
double denom = 0;
for (int i = 1; i < 2*n; i += 2) {
denom += i + i - 1;
double t = i / denom;
sum += t;
}
System.out.println("Sum = " + sum);
}
}Output

Answered By
2 Likes
Related Questions
Write a program in Java to find the Fibonacci series within a range entered by the user.
Sample Input:
Enter the minimum value: 10
Enter the maximum value: 20Sample Output:
13Define a class to accept a number and check whether it is a SUPERSPY number or not. A number is called SUPERSPY if the sum of the digits equals the number of the digits.
Example1:
Input: 1021 output: SUPERSPY number [SUM OF THE DIGITS = 1+0+2+1 = 4, NUMBER OF DIGITS = 4 ]Example2:
Input: 125 output: Not an SUPERSPY number [1+2+5 is not equal to 3]Which of the following are entry controlled loops?
(a) for
(b) while
(c) do..while
(d) switch
- only a
- a and b
- a and c
- c and d