Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

the same information whether it will connect to the database or it will be used previous information?

1032


What are various types of class loaders used by jvm?

979


Will the general public have access to the infobus apis?

1041


Name three component subclasses that support painting?

1065


What is ioc concept & explain it?

1080


Which characters may be used as the second character of an identifier, but not as the first character of an identifier?

1044


What is abstract schema?

1015


Why use a datasource when you can directly specify a connection details? (in a J2EE application)

4258


What is table mutation and how do you avoid it?

2459


What is the difference between long.class and long.type?

1088


Define aop(assepct oriented programing)?

1157


Are enterprise beans allowed to use thread.sleep()?

1144


Why use a datasource when you can directly specify a connection details?

1020


Is it possible to stop the execution of a method before completion in a sessionbean?

1077


Where can I ask questions and make suggestions about seam?

1054