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

How can I scroll through list of pages like the search results in google?

565


What does module-relative mean?

573


How database connectivity in XML is achieved?

1766


Explain about local interfaces.

580


What are transaction attributes?

610






Is the infobus client side only?

603


How task's priority is used in scheduling?

1779


What method is invoked to cause an object to begin executing as a separate thread?

572


What is the difference between the string and stringbuffer classes?

541


what is meant by JRMP?

1809


What’s jboss cache in short?

592


What is an abstract method?

590


What must a class do to implement an interface?

581


Difference between swing and awt?

596


Explain about RMI Architecture?

608