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
Write a program to show synchronization?
How to determine SGA site?
What is the difference between static and non-static with examples?
What are the sequence of steps to write pub or sub model kind of application?
Do I have to use jsps with my application?
What are the diff types of exception?
What is the purpose of the notifyall() method?
How will you pass parameters in RMI? Why do you serialize?
What value does read() return when it has reached the end of a file?
Name three component subclasses that support painting?
Is it possible to stop the execution of a method before completion in a sessionbean?
Why are my checkboxes not being set from on to off?
What are the design considerations while making a choice between using interface and abstract class?
What is the difference between a menuitem and a checkboxmenuitem?
Explain about local interfaces.