Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Fwd: Please spend 2 minutes
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Guru
Fwd: Please spend 2 minutes
1 Answer(s)      4 years and 2 months ago
Posted in : Java Beginners


Fresher to Java...getting some problem with getting output for this program

1+1/2+1/3+......+1/n.

please if possible send it to me

Advertisement
View Answers

August 27, 2010 at 1:31 PM


Hi Friend,

Try the following code:

import java.util.*;

public class SumOfSeries {

public static double sum(int n) {
if (n == 1)
return 1.0;
return sum(n - 1) + 1.0 / n;
}

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter number of terms :");
int num = input.nextInt();
System.out.println(sum(num));
}
}

Thanks


Related Tutorials/Questions & Answers:
Fwd: Please spend 2 minutes - Java Beginners
Fwd: Please spend 2 minutes  Fresher to Java...getting some problem with getting output for this program 1+1/2+1/3+......+1/n. please if possible send it to me   Hi Friend, Try the following code: import
javascript add minutes to time.
javascript add minutes to time.  I want to add minutes to time. How...;title>Add minutes to current times</title> <script type="text/javascript... = todayDate.getHours(); var minutes = todayDate.getMinutes(); var newMins
Advertisements
Java add minutes to Date
Java add minutes to Date In this tutorial, you will learn how to add minutes... used in date time manipulation. Here, we are going to add few minutes... add() of Calendar class, we have added 56 minutes to the calendar which
converstion from minutes to days format
converstion from minutes to days format  i have one text field ,in that it taking time in seconds for example 1560 seconds,but i need in the format like example: 09days:10 hrs:10 mins. i need code for change this thankls
how to print of hours and minutes of 8725 seconds
how to print of hours and minutes of 8725 seconds  how to print of hours and minutes of 8725 seconds
how many hours and minutes in 8725 seconds
how many hours and minutes in 8725 seconds  how many hours and minutes in 8725 seconds? Thanks
10 Minutes Guide to Ant
10 Minutes Guide to Ant       Introduction Well for the next 10 minutes get ready to devote to the ant guide. This will make some sence to the ant. Ant is a free tool under
in an application one task has to done for every 15 minutes ? How con you do it?
in an application one task has to done for every 15 minutes ? How con you do it?  in an application one task has to done for every 15 minutes ? How con you do
use is of 2
use is of 2  why we use 2 in "Integer.parseInt(str,2);" for binary to decimal conversion..??   ya i got it... because binary contain only two o and 1...so here use 2...same as octal has 8
Magicbox 2
Magicbox 2  how to build this? import java.util.*; class magicbox...; } } } } v15=a[0][0]+a[0][1]+a[0][2]==15 && a[1][0]+a[1][1]+a[1][2]==15 && a[2][0]+a[2][1]+a[2][2]==15 &&
Struts 2
Struts 2  we can extend DispatchAction class to implement a common session validation in struts 1.x. how to do the same in the struts2
Struts 2
Struts 2   I am just new to struts 2 and need to do the task. I have a requirement like this : when i click on link like Customer... button and user needs to select the rows to edit or delete. Please help me the code
Struts 2
Struts 2  I am getting the following error.pls help me out. The Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has
new 2
new 2  <%@page import="java.util.ArrayList"%> <%@page...; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2 sevelet @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@2 import java.io.IOException; import java.io.PrintWriter; import
Echo 2
Echo 2       Echo 2 allows you to code Ajax apps in pure Java (Demo)which automatically generates HTML and Javascript. Read full Description
FireFox 2
FireFox 2       The award... to do on the Web, and Firefox 2 is full of helpful features to make your... Add-ons that enhance Firefox. It?s easy to personalize Firefox 2
Thunderbird 2
Thunderbird 2       Mozilla?s Thunderbird 2 email application is more powerful than ever. It?s now... Information Organized Thunderbird 2 features many new enhancements to help
struts 2 testing
struts 2 testing  can i get an example for struts 2 action class unit test
regarding struts 2
regarding struts 2   is it not possible to get values from applicationresources.properties into our application in struts 2
Struts 2 - Validation - Struts
Struts 2 - Validation annotations  digging for a simple struts 2 validation annotations example
Program to read 2 integers using oops concepts
Program to read 2 integers using oops concepts  Write a program... in a similar way, so that 345 represents three hours and 45 minutes. ? This duration... notation, in this case 1630 which is the time 3 hours and 45 minutes after 12.45.
2's Complement
2's Complement  hi Can anyone plsss tell me the 2's complement java program... Thanks in advance
Where to learn Struts 2?
Where to learn Struts 2?  Hi, I am beginner in Struts and trying to find good tutorial to learn Struts 2 framework. My project is in Struts 2 and soon I have to work on the project. Let's know where to learn the Struts 2
Struts 2 Video Tutorial
Struts 2 Video Tutorial  I think its easy to learn from Struts 2 Video Tutorial. What is the url of Struts 2 Video Tutorial on roseindia.net website... your are right. You can learn Struts 2 very easily with the Struts 2 Video
Struts 2 online tutorial
Struts 2 online tutorial  Where to learn struts 2 online tutorial? Is there any good tutorials on roseindia.net for learning struts 2 online tutorial?   Yes, We have many tutorials for learning Struts 2 online through
What is Struts 2 framework
What is Struts 2 framework  Hi, I am new to the Java web programming. I have completed JSP, Servlet and HTML. Now I want to learn Struts 2. Tell me what is Struts 2? Thanks
Struts 2 + hibernate
Struts 2 + hibernate  How to integrate Struts 2 and Hibernate? Its urgent please help!!   See the example give below.. for integrating struts 2 and hibernate. Struts2.2.1 and hibernate integration application Integrate
Struts 2 + Hibernate
Struts 2 + Hibernate  From where can i get good tutorial from integrating struts 2 with hibernate , which explains step by step procedure in integration and to build web applications
struts 2 project samples
struts 2 project samples  please forward struts 2 sample projects like hotel management system. i've done with general login application and all. Ur answers are appreciated. Thanks in advance Raneesh
Strurt 2 TLD - WebSevices
Strurt 2 TLD  pls any one can send me either link to download or actual TLD files of struts 2 i nead the TLD files but i could not found
 

 

 

DMCA.com