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
What is the difference between RMI registry and OS Agent?
How to implement dphibernate to activate lazy loading in Flex with java ?thanx in advance!
wahts is mean by dynavalidatorform in struts/
What are the design considerations while making a choice between using interface and abstract class?
difference between ejb,struts,hibernate,spring and jsp
What are the pros and cons of detached objects?
which book is better for jdbc ,servlets and jsp
How many times may an objects finalize() method be invoked by the garbage collector?
What are the different types of exception?
In inglish: How to convert jar to exe files? Em português: Como converter arquivos .jar para .exe?
How task's priority is used in scheduling?
Name the class that is used to bind the server object with RMI Registry?
we use MainFrame and using os390 for operating system with DB2 data base in IRAN and interest programing with java and use webspere for world wide,please help me where i should start?
How substring() method of string class create memory leaks?
Name three subclasses of the component class?