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 would you detect a keypress in a jcombobox?
What class is the top of the awt event hierarchy?
Why is string immutable in java?
If your ui seems to freeze periodically, what might be a likely reason?
the same information whether it will connect to the database or it will be used previous information?
How to deploy Jar, War files in J2EE?
what is meant by JRMP?
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?
what are getters and setters in Java with examples?
What are callback interfaces?
Are there books about seam?
Which are the different segments of memory?
What is the purpose of the finally clause of a try-catch-finally statement?
What are the benefits of detached objects?
wahts is mean by dynavalidatorform in struts/