Write a java program to find out the sum of harmonic series :
1 + ½ + 1/3 + ……… up to nth term , for any value of n.

Answer Posted / sourav dey

import java.io.*;
class Hermonic{
public static void main(String args[]){
BufferedReader in=new BufferedReader(new
InputStreamReader(System.in));
double result = 0.0;
int num=0;
try{
System.out.println("Enter a term which you want to sum:");
num = Integer.parseInt(in.readLine());
}
catch(Exception e){}
while(num > 0){
result = result +( (double) 1 / num);
num--;
}
System.out.println("Output of Harmonic Series is "+result);
}
}

Is This Answer Correct ?    12 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Write a program to show synchronization?

700


How to determine SGA site?

1920


What is the difference between static and non-static with examples?

1366


What are the sequence of steps to write pub or sub model kind of application?

1901


Do I have to use jsps with my application?

591






What are the diff types of exception?

569


What is the purpose of the notifyall() method?

619


How will you pass parameters in RMI? Why do you serialize?

710


What value does read() return when it has reached the end of a file?

560


Name three component subclasses that support painting?

624


Is it possible to stop the execution of a method before completion in a sessionbean?

611


Why are my checkboxes not being set from on to off?

652


What are the design considerations while making a choice between using interface and abstract class?

553


What is the difference between a menuitem and a checkboxmenuitem?

597


Explain about local interfaces.

603