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
Is “abc” a primitive value?
AS a developer will u create a data source in connection pool? If so how will u do that, how to access the object from connection pool using IRAD tool?
What restrictions are placed on the values of each case of a switch statement?
Explain what is orm?
What if the static modifier is removed from the signature of the main method?
In inglish: How to convert jar to exe files? Em português: Como converter arquivos .jar para .exe?
what is handle?
Explain about thread synchronization inside a monitor?
What is ioc concept?
What are the call back methods in entity bean?
Explain ioc concept?
Describe, in general, how java's garbage collector works?
How task's priority is used in scheduling?
Is the infobus client side only?
What is the purpose of the notify() method?