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
How can I scroll through list of pages like the search results in google?
What does module-relative mean?
How database connectivity in XML is achieved?
Explain about local interfaces.
What are transaction attributes?
Is the infobus client side only?
How task's priority is used in scheduling?
What method is invoked to cause an object to begin executing as a separate thread?
What is the difference between the string and stringbuffer classes?
what is meant by JRMP?
What’s jboss cache in short?
What is an abstract method?
What must a class do to implement an interface?
Difference between swing and awt?
Explain about RMI Architecture?