Other Homework Help
Other Homework Help. Fibonacci Number
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; } }
"Our Prices Start at $11.99. As Our First Client, Use Coupon Code GET15 to claim 15% Discount This Month!!"
![](https://courseworkgeeks.com/wp-content/uploads/2018/08/order_now-1.png)