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
which type of objects reference will be given to client?
What are the purpose of introspection?
What is the immediate superclass of the applet class?
For which statements does it make sense to use a label?
What are externizable interface?
Can I run seam with jdk 1.4 and earlier?
How are the elements of a cardlayout organized?
What are the pros and cons of detached objects?
What value does readline() return when it has reached the end of a file?
What is chat area? Explain.
How many times may an objects finalize() method be invoked by the garbage collector?
Explain phantom read?
cud u help me ... i am struggling with this question... to find all the subsets of a given set for ex.... a,,b,c shud give all the subsets.... i gt the program in c bt nt able to get it in java..... help needed ..
What are the different algorithms used for clustering?
What is a modular application? What does module-relative mean?