/* related posts with thumb nails */

A java program to determine the sum of the following harmonic series for a given value of ‘n’. 1+1/2+1/3+. . . 1/n:

import java.io.*;

class ShowSum

{

public static void main(String as[]) throws Exception

{

InputStreamReader isr=new InputStreamReader(System.in);

BufferedReader br=new BufferedReader(isr);

System.out.println("Enter n value:");

int n=Integer.parseInt(br.readLine());

float sum=1;

for(int i=1;i<=n;i++)

sum=sum+(float)1/i;

System.out.println("Sum="+sum);

}

}

/* Output */

Enter n value:5

Sum=3.2833333

Related Topics:

3 comments:

koduri ramu said...

it show e errors symbol:class buffered reader location:class showsum

koduri ramu said...

it show e errors symbol:class buffered reader location:class showsum

Unknown said...

How to write this series in java program. 1 + 2/3 + 3/5 + 4/7 ....n


Post a Comment