Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2013
    Posts
    7
    Rep Power
    0

    Exclamation I really need help with this..

    Well I have the Fibonacci Number programming up and running very well and all I need to do is print the next 50 Fibonacci numbers along with the answer that I get, by the way I'm using eclipse, and here is the code:
    Java Code:
    import java.util.Scanner;
    
    public class FibonacciNumber {
    
    	private static Scanner console;
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		
    		//Variables
    		int previous1;
    		int previous2;
    		int current = 0;
    		int counter;
    		int nthFibonacci;
    		Object FubonacciNumber;
    		
    		Scanner console = new Scanner(System.in);
    		
    		//Prompt the user for input		
    		System.out.println("Enter the first Fibonacci number: ");
    		previous1 = console.nextInt();
    		
    		System.out.println("Enter the second Fibonacci number: ");
    		previous2 = console.nextInt();
    		
    		System.out.println("The first two numbers of the Fibonacci sequence are: " 
    		+ previous1 + "and" + previous2);
    		
    		System.out.println("Enter the position of the desired number in " +
    		"the Fibonacci sequence: ");
    		nthFibonacci = console.nextInt();
    		
    		
    		if (nthFibonacci == 1)
    			current = previous1;
    		else if (nthFibonacci == 2)
    			current = previous2;
    		else
    		{
    			counter = 3;
    			
    			while (counter <= nthFibonacci)
    			{
    				current = previous2 + previous1;
    				previous1 = previous2;
    				previous2 = current;
    				counter++;
    			}
    		}
    		
    		
    		System.out.println("\nThe " + nthFibonacci + "th Fibonacci number of "
    				+ "the sequence is: " + current);
    			}
    	private static int nextInt(int counter) {
    		// TODO Auto-generated method stub
    		return 0;
    	}
    }

  2. #2
    Kuttappu's Avatar
    Kuttappu is offline Member
    Join Date
    Aug 2011
    Location
    Kerala, India
    Posts
    40
    Rep Power
    0

    Default Re: I really need help with this..

    Is this what you want? - after printing nth number it should print (n+1)th number to (n+50)th number in the series.

    If so try following code after line 56..

    Java Code:
    counter=0;
    while (counter < 50)
    {
    current = previous2 + previous1;
    previous1 = previous2;
    previous2 = current;
    System.out.println(current);
    counter++;
    }
    Last edited by Kuttappu; 06-25-2013 at 09:50 PM.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: I really need help with this..

    Quote Originally Posted by nu2programming View Post
    I really need help with this..
    Please go through the Forum Rules, particularly the third paragraph.

    @Kuttappu: Please go through the Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your psot accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Kuttappu's Avatar
    Kuttappu is offline Member
    Join Date
    Aug 2011
    Location
    Kerala, India
    Posts
    40
    Rep Power
    0

    Default Re: I really need help with this..

    @Kuttappu: Please go through the Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and edit your psot accordingly.
    Thank you Darryl.

    Actually, when i posted the code i searched how to put code in this editor, but could only find smileys, quotes, url, insert image, insert video etc.

    I suggest, it will be a good idea to place a "insert code" icon also in this editor along with others.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: I really need help with this..

    Quote Originally Posted by Kuttappu View Post
    I suggest, it will be a good idea to place a "insert code" icon also in this editor along with others.
    You can find that in the advanced editor.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    Kuttappu's Avatar
    Kuttappu is offline Member
    Join Date
    Aug 2011
    Location
    Kerala, India
    Posts
    40
    Rep Power
    0

    Default Re: I really need help with this..

    Thank you again. Now i got it..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •