/* 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:

2 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

Post a Comment