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

which type of objects reference will be given to client?

2245


What are the purpose of introspection?

931


What is the immediate superclass of the applet class?

819


For which statements does it make sense to use a label?

800


What are externizable interface?

786


Can I run seam with jdk 1.4 and earlier?

737


How are the elements of a cardlayout organized?

773


What are the pros and cons of detached objects?

743


What value does readline() return when it has reached the end of a file?

830


What is chat area? Explain.

759


How many times may an objects finalize() method be invoked by the garbage collector?

855


Explain phantom read?

1954


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 ..

1952


What are the different algorithms used for clustering?

770


What is a modular application? What does module-relative mean?

740