1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
olasank [31]
3 years ago
8

Fibonacci sequence has many applications in Computer Science. Write a program to generate Fibonacci numbers as many as desired.

After the construction, you can print the sum value of the sequence. The example is below and user input is in boldface. Enter the number of terms: 6 First 6 terms of Fibonacci numbers are: 0 1 1 2 3 5 The sum value of the above sequence is: 12 Fibonacci sequence: First few numbers are 0, 1, 1, 2, 3, 5, 8 etc., except first two terms in sequence every other term is the sum of two previous terms, For example 8 = 3 + 5 (addition of 3, 5).
Computers and Technology
1 answer:
choli [55]3 years ago
5 0
<h2>Answer:</h2>

//import Scanner class

import java.util.Scanner;

//Class header definition

public class Fibonacci_Series {

   //main method    

   public static void main(String[] args) {

       //create an object of the Scanner class to allow for user's input

       Scanner input = new Scanner(System.in);

       //Ask the user to enter the number of terms

       System.out.println("Enter the number of terms");

       //Assign user input to a variable

       int nTerms = input.nextInt();

       //Declare and initialize to zero a variable sum to hold the sum of the series.

       int sum = 0;

       //Show message

       System.out.println("First " + nTerms + " terms of Fibonacci numbers are");

       

       //Create a for loop that cycles as many times as the number of terms entered by user

       //At every term (cycle), call the fibonacci method on the term.

       //And add the number to the sum variable

       for (int i = 1; i <= nTerms; i++){

         System.out.println(fibo(i));

         sum = sum + fibo(i);

       }   //End of for loop

       //show message

       System.out.println("The sum of the above sequence is ");        

       //Display the sum of the fibonacci series

       System.out.println(sum);

   }    //End of main method

   

   //Method fibo to return the nth term of the fibonacci series

   public static int fibo(int n){

       //if n = 1,  

       // the fibonacci number is 0

       if (n <= 1){

           return 0;

       }

       //if n = 2,  

       // the fibonacci number is 1

       else if(n == 2){

           return 1;

       }

       //if n > 2, fibonacci number is the sum of the previous two numbers

       else {

           return fibo(n-1) + fibo(n-2);

       }

   }   // End of method fibo

}    // End of class declaration

<h2>Sample Output:</h2>

<em>Enter the number of terms</em>

>> 6

<em>First 6 terms of Fibonacci numbers are</em>

0

1

1

2

3

5

<em>The sum of the above sequence is  </em>

12

<h2 /><h2 /><h2>Explanation:</h2>

The above code has been written in Java.

The code contains comments explaining important parts of the code. Kindly go through the comments for better readability and understanding.

The source code file of this question has been attached to this response. Please download it and go through it for better formatting.

Download java
You might be interested in
write an algorithm that gets the price for item A plus the quantity purchased. The algorithm prints the total cost, including a
I am Lyosha [343]

Answer:

<u>Algorithm() </u>

1. p = Enter the price of item A.

2. c = Enter the number of A’s purchased.

3. Now the price per item with tax is:

              t= p+(p*6/100)

4. The total cost of c items:  

             ct= t * c.

5. Print ct.

In this algorithm, we are taking the price per item and counting it’s cost including tax. Then we are multiplying the price per item with tax with the number of items we purchase, to find the overall cost with tax.

You may calculate the overall cost without tax as (p*c). Then you can find the overall cost with tax as ((p*c)+(p*c*6/100)), as in both way, we will get the same result.

4 0
3 years ago
HELP ME PLEASE
seraphim [82]

Answer:

Questions and answers

Explanation:

3 0
3 years ago
The ______________________ is the part of the ip address that is the same among computers in a network segment.
kozerog [31]
The answer is 
External IP address.
4 0
4 years ago
After installing the processor, if the system begins the boot process and suddenly turns off before completing the boot, the pro
NikAS [45]

Answer:

A. True

Explanation:

Be sure your processor is receiving sufficient cooling by verifying if there is a heatsink on it. If there is, make sure that it's inserted fully into cpu_fan port on the motherboard. If the boot process still turns off, you may have a defective processor or replace the motherboard.

8 0
4 years ago
How to learn python ?
laila [671]

Answer:

https://www.python.org/about/gettingstarted/

Explanation:

its a site i used

7 0
3 years ago
Other questions:
  • Stealing passwords by using software code to run through various password schemes with numbers, symbols, capital letters, and ch
    6·1 answer
  • A major difference between digital librarians and traditional librarians is that traditional librarians rarely work with people.
    15·2 answers
  • Ricardo twists his ankle at work but does not immediately realize that he is injured because his ankle is not sore or swollen, a
    5·1 answer
  • I'm looking for a new laptop for school. Which laptop would be the best. Right now I have a chromebook and it is broken. 
    12·2 answers
  • Who are the four main antagonists in fnaf 1
    13·2 answers
  • The Internet may best be compared to a/an
    11·1 answer
  • What will you see on the next line?
    6·2 answers
  • A game developer is purchasing a computing device to develop a game and recognizes the game engine software will require a devic
    7·1 answer
  • Which are the 2 main elements that’s make up computer architecture?
    6·2 answers
  • Sharon's company has written a new computer program, and she has been asked to find a way to prevent people from copying the sof
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!