Fibonacci Number

User Generated

ah2h

Other

Description

I have a Fibonacci number program in java and it works very well, I just want it to give me the following 50 Fibonacci numbers when I get my answer. How do I program it to do that? here's my 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; } }


User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

Thank you for the opportunity to help you with your question!

you can not ask such a long question in free zone 

I can do your assignment, Assignment will be fresh and original, that's my guarantee . If you want any sample work I can provide you . Waiting for positive reply . Thanks

Please let me know if you need any clarification. I'm always happy to answer your questions.


Anonymous
I was stuck on this subject and a friend recommended Studypool. I'm so glad I checked it out!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4

Related Tags