C Programs Tutorials | IT Developer
IT Developer

Java Programs



Share with a Friend

Sum of Series Program - Java Programs

Write a program to compute and display the sum of the following series:

import java.io.*; class Series{ public static void main(String args[])throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.print("N = "); int n = Integer.parseInt(br.readLine()); double sum = 0.0; for(int i = 2; i <= n + 1; i++){ int p = 1; double s = 0; for(int j = 1; j <= i; j++){ p *= i; s += i; } sum += s / p; } System.out.println("Sum = " + sum); } }

Output

 
 OUTPUT  : 
N = 10
Sum = 1.404668597605295