Can some one answer this please using the instructions below

Can some one answer this please, using the instructions below.

The problem reads:

Prompt the user for the number of values in Fibonacci the user wants to see. The sequence may be produced by using the last two values in the sequence to produce the next value. Start the sequence with 0 and 1. The next value in the sequence would be 1 (= 0 + 1). The next value would be 2 (= 1 + 1) and the value following would be 3 (= 1 + 2).

A typical session might look like this...

How many Fibonacci numbers do you want to see? 9

The Fibonacci sequence for 9 numbers is...
0, 1, 1, 2, 3, 5, 8, 13, 21

Thank you

Notes:

Develop your solution using Java.

Use the prompt and reply sequence to determine the number of values in the sequence to display (make a minimum of 12).

Consider the most appropriate data type to use for the values in the sequence. Consider and implement any tests necessary to insure the user response is valid (ie, numeric and greater than or equal to 12).

Hand calculate your sequence to confirm your program works properly. Append your prompt & reply sequence with the sequence produced at the end of your program using the comment convention for Java.

Submit the source program and the test data set document for credit.

This is what i have so far, not sure if its right, can you complete it please.

public class Fibonacci {

   public static void main(String[] args) {
       int n1 = 0, n2 = 1, n3, i, count = 8;
      
       System.out.print(n1 + \" \" + n2);
      
       for(i = 2; i < count; ++i);
      
       {
       n3 = n2 + n2;
       System.out.print(\" \" + n3);
       n1=n2;
       n2=n1;
      
       }
      

   }

}

Solution

Fibonacci.java

import java.util.Scanner;

public class Fibonacci {
public static void main(String[] args) {
int n1 = 0, n2 = 1, n3, i, count;
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter the number of values you want to see: \");
count = scan.nextInt();

System.out.print(n1 + \" \" + n2);
  
for(i = 2; i < count; ++i)
  
{
n3 = n1 + n2;
System.out.print(\" \" + n3);
n1=n2;
n2=n3;
  
}
  
}
}

Output:

Enter the number of values you want to see:
8
0 1 1 2 3 5 8 13

Can some one answer this please, using the instructions below. The problem reads: Prompt the user for the number of values in Fibonacci the user wants to see. T
Can some one answer this please, using the instructions below. The problem reads: Prompt the user for the number of values in Fibonacci the user wants to see. T

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site