Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-06-2008, 07:02 AM
Zosden's Avatar
Senior Member
 
Join Date: Apr 2008
Posts: 386
Zosden is on a distinguished road
Iterative Algorithms
This is a sample of the iterative approach to Fibonacci numbers.

Code:
/** * @(#)FibonacciNumbers.java * * * @author * @version 1.00 2008/5/5 */ public class FibonacciNumbers { public FibonacciNumbers(long n) { System.out.println("Your number is: " + this.findNumbers(n)); } private long findNumbers(long n) { long temp1 = 1; long temp2 = 0; long fibonacciNumber = 0; for (long i = 2; i <= n; i++) { fibonacciNumber = temp1 + temp2; temp2 = temp1; temp1 = fibonacciNumber; } return fibonacciNumber; } public static void main(String[] args) { FibonacciNumbers fibNum = new FibonacciNumbers(190); } }
the number this will work for is 190
__________________
My IP address is 127.0.0.1
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-05-2008, 07:29 AM
schweinstEIGER's Avatar
Member
 
Join Date: Jul 2008
Location: Medan - Indonesia
Posts: 2
schweinstEIGER is on a distinguished road
Hm, i think it is wrong. If n=190 the fibNum is more than 18 digit, while long int only 18 digit...

n = 190 , fibnum is more than 19 digit while long int has only 18 digit, what is the fibonacci of 100? The answer is 354224848179261915075 and it's more than 19 digit...

I think it is wrong. If(n==190) the answer is more than 19 digit while long only 19 digit...

CMIIW..

Last edited by CaptainMorgan : 08-01-2008 at 08:18 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply

« Recursion | - »

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Algorithms and data from a File Problem BHCluster Advanced Java 0 04-18-2008 05:38 PM


All times are GMT +3. The time now is 04:23 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org